From SASS docs:
You can also use interpolation in a calculation. However, if you do, nothing in the parentheses that surround that interpolation will be simplified or type-checked, so it’s easy to end up with extra verbose or even invalid CSS. Rather than writing calc(10px + #{$var}), just write calc(10px + $var)!
But when I try to compile that
$var: 10px;
span {
top: calc(10px + $var); // without interpretation
bottom: calc(10px + #{$var}); // with interpretation
}
I get this:
span {
top: calc(10px + $var); // obviously wrong
bottom: calc(10px + 10px);
}
If I understand docs correctly, top should have assigned value 20px. Without interpretation, calc should be called as internal SASS function and return value. Why it didn't happen? How do I calculate without interpretation?
OK, I figured it out myself. There are two things:
calc(10px + $var)but simply10px + $var;So this is how it should be written in SASS:
It will properly compile to:
Regarding values of
topandbottom: they are correct. SASS treatscalc(10px + $var)as raw string and simply copies it and treatscalc(10px + #{$var});as string with interpolated value which it interpolates and then writes to the resulting CSS.So everything is OK but the SASS docs are misleading.