2012-04-26 81 views
0

我試圖給我的列表中的每個%li標籤指定一個不同的background-color。我希望這些顏色既可以使用某種顏色的陰影,也可以使用兩種顏色之間的漸變。很像這麼受歡迎的Clear。我熟悉用sass減輕和加深顏色的能力...Sass顏色函數列表漸變

$this_color: darken($that_color, 10%) 

但除此之外,我不知道如何創建我期待的效果。視覺這裏是我想做的事:

%ul 
    %li full color 
    %li darken 5% 
    %li darken 10% 
    ... 

回答

2
// set your color 
$backgroundColor: red 

// set the scale/increment for the function 
$backgroundColorScale: 8 

// number of items in your list 
$numberOfItemsInList: 10 

// here's a custom function to change the color 
// but you could make this fairly advanced 
// and shift color, saturate, etc. 
@function -modify-bg($bgcolor, $counter, $depth: $backgroundColorScale) 
    @return lighten($backgroundColor, ($i * $backgroundColorScale)) 

// here's the loop that steps through LIs and assigns each a new bg 
$i: 0 
@while $i < $numberOfItemsInList 
    li:nth-child(#{$i}) 
    background-color: -modify-bg($backgroundColor, $i) 
    $i: $i + 1 
改變顏色一個接一個的一種方式