0
@color-purple: "#ffffff"
@colors: purple, light-purple, green, light-green, red, light-red, grey, light-grey, lightest-grey;
.ColorsMixin(@i:0) when(@i =< length(@colors)){ //loop over icons array
@color: extract(@colors, @i); //extract the icon at current index @i
[email protected]{color}{
background: @{[email protected]{color}};
&:before{
content: "@{color}";
}
&:after{
content: "\@{[email protected]{color}}";
}
}
.ColorsMixin(@i + 1);
}
.ColorsMixin();
所以,我可以得到它做什麼,我想在與字符串變量串聯,形成另一個變量
content: "\@{[email protected]{color}}";
部分做。這將輸出
content: "#ffffff";
然而,當我嘗試輸出@色紫色變量爲背景,LESS拋出一個錯誤。它似乎工作,如果我用引號包裝它,但背景屬性希望十六進制代碼沒有引號周圍。
這裏有什麼竅門?
感謝您的意見。當使用〜'@ {color - @ {color}}'時,我實際上最終得到錯誤; 錯誤提示:未知單詞 。顏色 - 提取物(紫色,淺紫色,綠色,淺綠色,紅色,淺紅色,灰色,淺灰色,最淺灰色,0){ background:@ {顏色提取(紫色,淺紫色,綠色,淺綠色,紅色,淺紅色,灰色,淺灰色,最淺灰色,0)}; (^其中顏色來自@colors數組,我在這個例子中簡化了) 但是你建議有2個列表,所以我會研究一下。謝謝 – nicedevman
你錯誤的是用0作爲起始索引。少於起始索引是1(僅僅因爲它在CSS本身就是這種方式)。 *但你建議有2個列表* - 不是2 - 只有一個(例如[這裏](例如https://stackoverflow.com/questions/20954762))。 –