我正在生成几个列类,其宽度在Sass映射中定义,如下所示:
$column-widths: 5 10 20 25 30 33 40 50 60 66 70 80 90 100;
@each $width in $column-widths {
.column-#{$width} {
width: #{$width}%;
}
}
但是,我在编译时收到此错误:
Error in plugin 'sass'
Message:
grid.scss
Error: Invalid CSS after "...dth: #{$width}%": expected expression (e.g. 1px, bold), was ";"
on line 10 of grid.scss
>> width: #{$width}%;
----------------------^
看起来它并没有像我预期的那样解释这个。我想在百分号之前插入数字值。但我认为它是将它们作为字符串读取,然后尝试评估百分比并且只是感到困惑。
答案 0 :(得分:4)
找出正确的方法。我应该使用Sass中的百分比函数而不是插值。
$column-widths: 5 10 20 25 30 33 40 50 60 66 70 80 90 100;
@each $width in $column-widths {
.column-#{$width} {
width: percentage($width / 100);
}
}