第n($list,$n)`的sass参数`$n`必须是一个数字
在sass列表中,索引值是否可以用变量表示第n($list,$n)`的sass参数`$n`必须是一个数字,sass,Sass,在sass列表中,索引值是否可以用变量表示 $colors:#111 #222 #333 #444; @for $i from 1 through 4 { :nth-child(#{$i}):after{ background: nth($colors, #{$i}); } } 在sassnth(颜色,索引)中,索引可以使用变量吗 是。您只是在语法上有一些问题,并且还没有定义“what”的第n个子项。此示例显示如何将sass应用于列表项。这还使用数组的长度来确定循环的数量
$colors:#111 #222 #333 #444;
@for $i from 1 through 4 {
:nth-child(#{$i}):after{
background: nth($colors, #{$i});
}
}
在sass
nth(颜色,索引)
中,索引
可以使用变量吗 是。您只是在语法上有一些问题,并且还没有定义“what”的第n个子项。此示例显示如何将sass应用于列表项。这还使用数组的长度来确定循环的数量,而不是手动将其设置为4,从而使代码更加经得起未来的考验
$colors: #111 #222 #333 #444;
@for $i from 1 through length($colors) {
li:nth-child(#{length($colors)}n+#{$i}) {
background: nth($colors, $i);
}
}
你可以用地图代替
$colors: (
red: 1,
green: 2,
blue: 3,
orange: 4
);
@each $color, $child in $colors {
li:nth-child(#{$child}n) {
background: $color;
}
}