在LESS中使用选择器中的变量

cal*_*rae 7 less

我有一个变量@index,我想输出一个选择,这样,当@index3时,选择是[data-sth="3"].

更长的例子:

@index: 3;
/* selector here */ {
    color: red;
}
Run Code Online (Sandbox Code Playgroud)

期望的输出:

[data-sth="3"] {
    color: red;
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一些东西,但还没有设法得到任何有效的东西.

谢谢.

cal*_*rae 9

请参见可变插值.即:

[data-sth="@{index}"] {
    color: red;
}
Run Code Online (Sandbox Code Playgroud)

原始答案(1.40之前的更少版本):

以下代码应该有效:

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

~删除引号.