问题
In my less file I define a variable theme colour as: @primaryColour: red;
But when the id of my body changes, I want to change the overall theme colour to '@primaryColour: blue;
How do I re-define this theme colour? This doesn't work:
@primaryColour: red;
body#secondTheme {
@primaryColour: yellow;
}
回答1:
You cannot overwrite variables in LESS (within the same scope). The documentation specifically says:
Note that variables in LESS are actually ‘constants’ in that they can only be defined once.
I suggesr you tu use something like this:
.colorDefs(@color) {
@primaryColour: @color;
}
body#firstTheme {
.colorDefs(red);
}
body#secondTheme {
.colorDefs(yellow);
}
来源:https://stackoverflow.com/questions/18462295/less-css-change-theme-variable-in-case-of-id