2013-06-12 36 views
0

我正在更新一些舊的CSS工作表併爲我的項目創建一個新的LESS工作表。在舊的CSS表格中,我有兩個用於製作漸變的十六進制值。LESS變量值爲字符串

十六進制值傳遞像十六進制值的一個實例是這樣的:

background: -webkit-gradient(linear, left top, left bottom, from(#0079bc), to(#00509d)); 

而在另一個實例中相同的規則是這樣的字符串值:

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00509d', endColorstr='#00509d'); 

如果我試圖在新的LESS文件中將這兩個十六進制值保存爲變量,我如何在第二個實例中將十六進制值變量作爲字符串傳遞?

回答

1

事情是這樣的:

.gradientMix(@hex1, @hex2) { 
    background: -webkit-gradient(linear, left top, left bottom, from(@hex1), to(@hex2)); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='@{hex1}', endColorstr='@{hex2}'); 
} 

.gradientMix(#0079bc,#00509d); 

,輸出:

background: -webkit-gradient(linear, left top, left bottom, from(#0079bc), to(#00509d)); 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0079bc', endColorstr='#00509d'); 

注意我是如何訪問的變量時,它是在引號內用方括號包圍的名字,像這樣:@{hex1}到訪問字符串內的@hex1變量。