Calculate a percent with SCSS/SASS

Nick Ginanto picture Nick Ginanto · Nov 13, 2012 · Viewed 90.4k times · Source

I want to set a width in percentage in scss via calculation, but it gives me errors..

Invalid CSS after "...-width: (4/12)%": expected expression (e.g. 1px, bold), was ";"

I want to do something like

$my_width: (4/12)%;

div{
width: $my_width;
}

how do I add the % sign in there?

Same question with px and em

Answer

Tomas picture Tomas · Nov 13, 2012

Have you tried the percentage function ?

$my_width: percentage(4/12);
div{
width: $my_width;
}