2013-08-25 63 views
2

我有4个列表项目,每个项目需要不同的背景颜色。第n个项目的无限循环

我可以把我的4级不同颜色的变量在萨斯列表以及对通过它们作为$color但在循环的内容块我显然需要指定其<li>我谈论使用:nth-of-type 1,2,3或4 。

我不确定如何指定在每一次循环中我需要哪个<li>

任何想法?

回答

8

这应该做的伎俩:

$colors: (#000, #F00, #0F0, #00F); 
@for $i from 1 through length($colors) { 
    li:nth-of-type(#{$i}) { 
     background: nth($colors, $i); 
    } 
} 

它产生:

li:nth-of-type(1) { 
    background: black; } 

li:nth-of-type(2) { 
    background: red; } 

li:nth-of-type(3) { 
    background: lime; } 

li:nth-of-type(4) { 
    background: blue; }