问题
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;
}
...
Is this possible?
回答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
来源:https://stackoverflow.com/questions/34410889/stylus-iteration-interpolation-with-nth-of-type