scss 遍历数组
文章目录
each遍历
$colors: (
#00D477,
#F57933,
#0052F5
);
@each $c in $colors {
$i: index($colors, $c);
.tag-#{$i} {
background-color: $c;
}
}生成的结果如下:
.tag-1 {
background-color: #00D477;
}
.tag-2 {
background-color: #F57933;
}
.tag-3 {
background-color: #0052F5;
}
for循环
$colors: (
#00D477,
#F57933,
#0052F5
);
@for $i from 1 to 4 {
.tag-#{$i} {
background-color: nth($colors, $i)
}
}生成结果与上方一样,要注意的是to循环不到4
另外to换成through,但是后者可以走到4
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论