【发布时间】:2016-01-05 18:16:24
【问题描述】:
我想定义类
.bg-1 {
width: 1%
}
.bg-2 {
width: 2%
}
我正在尝试这个:
@for $i from 1 through 100 {
.bg-#{$i} {
width: #{$i};
}
}
这至少可以编译,但会打印出来
.bg-1 {
width: 1;
}
.bg-2 {
width: 2;
}
问题是如果我添加:
width: #{$i}%;
我明白了:
error sass/screen.scss (Line 294 of sass/modules/_classes.scss: Invalid CSS after " $var: ": expected expression (e.g. 1px, bold), was "%;")
【问题讨论】:
-
试试
width: #{$i} + '%';或width: #{$i}'%'; -
这会生成
.bg-95{width:95+"%"}或.bg-95{width:95"%"}... -
@cimmanom 如果你的意思是我应该
$percent: 1%然后 'width: #{$i}*$percent;` 我在问之前试过......结果是.bg-95{width:95*1%"}跨度>