I want to create something like a themepicker. I use LESS.css.
LESS.css has a variable which contains the main colors :
@colorOne: #222;
@colorTwo: #fff;
@darkGradientStart: lighten(@colorOne, 10%);
@darkGradientStop: lighten(@colorOne, 5%);
@lightGradientStart: @colorTwo;
@lightradientStop: darken(@colorTwo, 7%);
I want to change them if the tag has the color-class like this:
<body class='theme-blue'>
then I have written this in my less.css (after the default variables)
.theme-blue{
@colorOne: blue;
}
but it still uses the default #222. It is not overwritten.
How can I solve this problem?
Thanks
You cannot overwrite variables in LESS (within the same scope). The documentation specifically says:
For what you desire, you need to do a mixin:
Example LESS Code
Example CSS Output
Solving 4K (i.e. a lot of) Lines of Code
ed1nh0 commented about having 4K lines of code using the color variables, and not being able to “put that in a mixin.” Let me make a few comments on that:
.colorDefsis the same as above and not repeated here):LESS
The above does assume that there are not differences in how the variables are used by the properties, just what the values of those properties are. If there were any “differences,” then some tweaking mixins may need to be done for certain situations, but the concept should still hold.