Stylus Iteration + Interpolation with nth-of-type

匿名 (未验证) 提交于 2019-12-03 01:44:01

问题:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!