Dynamyc SCSS classes with % value
Hello, I'm replacing a deprecated Angular library and I'm trying to create a class in this way:
But it gives me error:
term expectedscss(css-termexpected)
. So I also tried: But it doesn't seem to apply any class. What am I doing wrong?8 Replies
Also tried: With the same result of solution #2: no class is applied on elements with
class="flex--fx-19"
Ok I solved it, but I'd still like to know what the best syntax is (I was missing a -
that's why it didn't work)why dont you multiply by 1%?
#{$value * 1%}
that's the best way i found to convert an unitless number to an unitOhh I wasn't aware of this trick, neat
it's just plain maths
by the way, you should be able to also do
+ 0%
, - 0%
or (in old versions) / 1%
but the * 1%
is the most obvious of them allYeah I like it
and if has type checking: if you try to do something dummy like
5px * 1%
, it will yell at youI see, I replaced it in my code :)
awesome!