【发布时间】:2019-04-08 21:04:33
【问题描述】:
我正在研究 SCSS 循环,但遇到了一个问题。问题是考虑颜色列表。
$colors:'red','green','red','blue';
@each $color in $colors{
$i:index($colors,$color);
.cube:nth-child(#{$i}){
background:$color;
};
}
上述程序的输出是
.cube:nth-child(1) {
background: "red";
}
.cube:nth-child(2) {
background: "green";
}
.cube:nth-child(1) { // issue here unable to get index value 3
background: "red";
}
.cube:nth-child(4) {
background: "blue";
}
我无法获得索引值 3。有人可以帮我解决这个问题吗? 我的问题是
- 如何获取索引值3?
- 是否可以使用 each 获取索引?如果“是”怎么办?
- 如果不是,还有什么替代方法?
【问题讨论】:
-
您希望
cube的颜色作为颜色列表(在同一索引中)吗? -
是的,我需要使用循环获取索引值 3。
-
好的,但是在 index=1 中颜色会在 2 绿色中变为红色...?
-
我正在为我的背景颜色使用硬编码值。我只想要索引值。现在离开背景颜色。
标签: html css web sass frontend