触控笔迭代+插入与nth-of-type [英] Stylus Iteration + Interpolation with nth-of-type
本文介绍了触控笔迭代+插入与nth-of-type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用通过如下项目列表循环时提供的计数器:
I'm attempting to use the counter provided when looping thru a list of items like so:
colors = red blue orange green yellow
li
for color, i in colors
&:nth-of-type({i}n)
background-color: color
这个例子不起作用,但我想要的输出是:
This example does not work, but the intended output I'm looking for is:
li:nth-of-type(1n) {
background-color: red;
}
li:nth-of-type(2n) {
background-color: blue;
}
li:nth-of-type(3n) {
background-color: orange;
}
...
这可能吗?
推荐答案
实际上你的例子的输出几乎是正确的。它从0开始,你需要1,所以这应该工作:
Actually your example's output is almost correct. It starts with 0 and you need 1, so this should work:
colors = red blue orange green yellow
li
for color, i in colors
&:nth-of-type({i + 1}n)
background-color: color
这篇关于触控笔迭代+插入与nth-of-type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文