I previously started working with SASS (scss to be specific) and was wondering, if there's any difference/advantage/disadvantage between the css calc() method or sass calculation?
$divide-by: 50;
//CSS calc()
.example1 {
height: calc(100vw / #{$divide-by});
}
//SASS calculation
.example2 {
height: 100vw / $divide-by;
}
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.
The calc() function performs a calculation to be used as the property value.
On top of using CSS variables in calc you can also convert a value that has no units to a value with units by just multiplying the value by 1 of the unit type you want to convert to. This is very useful if you have CSS variables being set in JS that do not include the unit.
SASS allows for mathematical operations such as addition, subtraction, multiplication and division.
SASS calculation is made on compilation. While CSS calc()
is always made on the browser.
For example:
SASS height: 100px / 2;
will compile to height: 50px;
<- and this is what the browser will see always no matter what.
CSS width: calc(100% - 20px)
will always be this even on the browser, and at that point the browser will do the calculations depending on what that 100% looks like.
in your case height: 100vw / $divide-by;
i belive you variable will be considered as a vw
value, so if $divide-by
is 20, then the compiles version of that height will be height: 5vw;
Let me know if the explanation did not help, and I will try to give you some resources to read.
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