I would like to do the following using SASS:
width: #{$percent}%;
Where $percent
is a variable containing a number. If $percent
is equal to 50, the precompiled CSS would be:
width: 50%;
What syntax should I use?
String Operators The single Sass string operator is concatenation. Strings can be concatenated (linked together) using the + operator. If you mix quoted and unquoted strings when concatenating, the result will be whichever is on the left side of the operator.
Interpolation allows us to interpolate sass expressions into a simple SASS or CSS code. Means, you can define ( some part or the whole ) selector name, property name, CSS at-rules, quoted or unquoted strings etc, as a variable. Interpolation is a new principle and it is widely used in SASS.
Multiply by 1%:
$percent: 50
.foo
width: $percent * 1%
Result:
.foo {
width: 50%;
}
If anyone is looking answer for SCSS below code will work perfectly, just use css calc.
$percent: 50
.foo{
width: calc(#{$percent} * 1%)
}
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