2012-04-14 55 views
7

我有一個變量@index,我想輸出一個選擇器,這樣當@index3時,選擇器是[data-sth="3"]在LESS中選擇器中使用變量

更長的例子:

@index: 3; 
/* selector here */ { 
    color: red; 
} 

所需的輸出:

[data-sth="3"] { 
    color: red; 
} 

我已經嘗試了一些東西,但沒有設法獲得任何工作,但。

謝謝。

回答

9

參見Variable Interpolation。即:

[data-sth="@{index}"] { 
    color: red; 
} 

原來的答覆(1.40今非昔比版本):

下面的代碼應該工作:

(~'[data-sth="@{index}"]') { color: red; }

~去掉引號。

+1

謝謝!這些parens也很重要。 – 2012-06-28 00:16:10