您需要将两个调用都嵌套到字符串中。我已经使处理全部通过一个新变量useColor
(您不必这样做,我只是认为它看起来更干净):
.setCat(@x) {
.cat@{x} {
@useColor: ~"@{catColor@{x}}";
.menu-link {
&.selected, &:hover { background: @useColor; }
&:hover:after { border-top-color: @useColor; }
&:only-child:after { border-top-color: transparent; }
}
.menu-link-submenu { background: @useColor; }
}
}
所以假设这个 LESS:
@catColor1: #fff;
@catColor2: #aaa;
.setCat(1);
.setCat(2);
产生这个 CSS:
.cat1 .menu-link.selected,
.cat1 .menu-link:hover {
background: #ffffff;
}
.cat1 .menu-link:hover:after {
border-top-color: #ffffff;
}
.cat1 .menu-link:only-child:after {
border-top-color: transparent;
}
.cat1 .menu-link-submenu {
background: #ffffff;
}
.cat2 .menu-link.selected,
.cat2 .menu-link:hover {
background: #aaaaaa;
}
.cat2 .menu-link:hover:after {
border-top-color: #aaaaaa;
}
.cat2 .menu-link:only-child:after {
border-top-color: transparent;
}
.cat2 .menu-link-submenu {
background: #aaaaaa;
}