See also: https://github.com/less/less.js/issues/2263
If you are enable to split @var into two (or more) separated variables you can use the following Less code:
@var1: ~"> a";
@var2: ~"> a:hover";
body > header {@{var1},@{var2} { > strong > em {color:red;}}}
The preceding will compile into the following CSS code:
body > header > a > strong > em,
body > header > a:hover > strong > em {
color: red;
}
When @var: "a", "a:hover";
you can also use:
@var1: e(extract(@var,1));
@var2: e(extract(@var,2));
body > header {
> @{var1}, > @{var2} {
> strong > em {
color: red;
}
}
}
Or use a complex mixin (as Bootstrap does, see: LESS loops used to generate column classes in twitter - How do they work?) to build your selectors:
.mixin(@iterator: 0; @selectors: ~""; @seperator: ~"") when (@iterator < length(@var)) {
@blah: ~"body > header > @{selector} > strong > em";
@selector: extract(@var,@iterator + 1);
@selectorlist: ~"@{selectors} @{seperator} @{blah}";
.mixin((@iterator + 1); @selectorlist; ~",");
}
.mixin(@iterator; @selectors: ~""; @seperator: ~"") when (@iterator = length(@var)) {
@{selectors} {
color:red;
}
}
.mixin();