0

I change a class on my body depending on what month we are actually in. This is going to change how my theme will behave. So what I want to do is to change my color variable into my .less file depending on those classes. This is what I tryed (and failed) to do.

...
body.january{
    @c_primary:<COLOR>;
    @c_secondary:<COLOR>;
    @c_text:<COLOR>;
}
body.february{
    @c_primary:<COLOR>;
    @c_secondary:<COLOR>;
    @c_text:<COLOR>;
}
...

Is there a way to do it?

Dynomite
  • 176
  • 1
  • 2
  • 14
  • remove dot (.) before second body – Donnie Apr 21 '17 at 15:24
  • 1
    This is impossible (because the preprocessor has no idea what your HTML is, thus it simply can't choose a variable depending on the class of your *HTML* element) - see http://stackoverflow.com/questions/11846237, http://stackoverflow.com/questions/1159952 etc. – seven-phases-max Apr 21 '17 at 15:44
  • By now you can use [native CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) for this kind of customization. – seven-phases-max Apr 21 '17 at 15:46
  • Oh well, thank you. I was worried that would be impossible. using "Can I use" somewhat still show limited support precisely on IE. that is sad. https://caniuse.com/#feat=css-variables – Dynomite Apr 21 '17 at 15:55
  • 1
    Well, as shown in the Q/As above it's not a problem to emulate this using a preprocessor (the only quirk is that it results in a bloating CSS result). For another example see also http://stackoverflow.com/questions/23551080 etc. - there're variety of methods actually ([another example](https://gist.github.com/seven-phases-max/553e3a0c69ce6fb76f63c2d173259185) for your snippet above). – seven-phases-max Apr 21 '17 at 17:32

0 Answers0