2015-12-22 21 views
0

我試圖使用循環直通像這樣的項目清單時提供的計數器:手寫筆+迭代插值第n-的型

colors = red blue orange green yellow 

li 
    for color, i in colors 
     &:nth-of-type({i}n) 
      background-color: color 

這個例子沒有工作,但預期輸出I尋找的是:

li:nth-of-type(1n) { 
    background-color: red; 
} 
li:nth-of-type(2n) { 
    background-color: blue; 
} 
li:nth-of-type(3n) { 
    background-color: orange; 
} 
... 

這可能嗎?

回答

1

其實你的例子的輸出幾乎是正確的。它從0開始,你需要1,所以這應該工作:

colors = red blue orange green yellow 

li 
    for color, i in colors 
     &:nth-of-type({i + 1}n) 
      background-color: color 
+0

Derp,謝謝 - 不知道我怎麼看這... – hhsnopek