Percentages in Sass work just like every other unit. They are not interchangeable with decimals, because in CSS decimals and percentages mean different things. For example, 50% is a number with % as its unit, and Sass considers it different than the number 0.5 .
Subtract the original value from the new value, then divide the result by the original value. Multiply the result by 100. The answer is the percent increase. Check your answer using the percentage increase calculator.
To calculate this you first start by summing up all the values in the set (∑x1... xn) and make this sum the denominator of a fraction. The number for which you want the percentage becomes the numerator. Convert to decimal form and multiply by 100 to get the percentage.
Have you tried the percentage function ?
$my_width: percentage(4/12);
div{
width: $my_width;
}
Another way:
$my_width: 4/12*100%;
div{
width: $my_width; // 33.33333%
}
Sass will output the value in %.
I was able to make it work this way:
div{
width: (4/12)* 1%;
}
This way you don't need to use any special function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With