Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate a percent with SCSS/SASS

Tags:

css

sass

People also ask

What is percentage in Sass?

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 .

How do you calculate a 200% gain?

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.

How do you calculate data handling percentage?

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.