在我的圈子里做数学。
@for $i from 1 through length($colors) {
ul li:nth-child(#{$i}) {
z-index: length($colors) - #{$i};
}
}
例如,我在CSS中得到的是:
li:nth-child(2) {
z-index: 8-2;
}
我怎么能强迫SASS做数学然后得到:
li:nth-child(2) {
z-index: 6;
}
谢谢你帮忙!
发布于 2014-09-10 10:43:49
您正在将$i值作为字符串放在z-index属性中。如果要正确计算值,则应执行以下操作:
$length: length($colors)
@for $i from 1 through length($colors) {
ul li:nth-child(#{$i}) {
z-index: $length - $i;
}
}
此外,我建议您设置一个具有长度值的变量,以防止对此函数的多次调用。
致以问候。
https://stackoverflow.com/questions/25760202
复制相似问题