Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS (sass) calculation: #{} [duplicate]

Tags:

css

sass

i'm quite confused at the moment when it comes to calculating a font-size

this is the normal calculation I already use.

font-size: #{($font-size*0.7) / $em}em

What I wanna do now is divide an entire statement like the one above with another one … sounds complicated I know.

So I have #{($font-size*0.7) / $em} And I have #{($font-size*0.8125) / $em}

I want to devide those two values now …

So font-size: #{($font-size*0.7) / $em} / #{($font-size*0.8125) / $em}em.

But that doesn't work. Any idea how I do a calculation like that with SASS?

like image 795
matt Avatar asked Aug 02 '12 18:08

matt


People also ask

How is SCSS calculated?

CSS calc() It can be used to calculate length, percentage, time, number, integer frequency, or angle. It uses the four simple arithmetic operators add (+), multiply (*), subtract (-), and divide (/). It is a powerful CSS concept because it allows us to mix any units, such as percentage and pixel.

Is Sass and SCSS the same?

SASS (Syntactically Awesome Style Sheets) is a pre-processor scripting language that will be compiled or interpreted into CSS. SassScript is itself a scripting language whereas SCSS is the main syntax for the SASS which builds on top of the existing CSS syntax.

Can you do math in sass?

Sass supports the standard set of mathematical operators for numbers. They automatically convert between compatible units. <expression> + <expression> adds the first expression's value to the second's.

How many syntaxes that sass support?

Sass consists of two syntaxes.


2 Answers

Try:

font-size: #{(($font-size*0.7) / $em) / (($font-size*0.8125) / $em)}em

The interpolation back into a string #{...} should be the last thing done after the calculations.

like image 145
ScottS Avatar answered Nov 02 '22 13:11

ScottS


ScottS answer appears to be technically correct, but why do you even need such a complex expression in the first place? Expressed as a fraction, this can be simplified to

($font-size * 0.7 / $em) / ($font-size * 0.8125 / $em) = 0.7 / 0.8125

And your final expression would be

font-size: #{(0.7/0.8125)}em

...wouldn't it?

like image 8
Oleg Avatar answered Nov 02 '22 13:11

Oleg