themes - Defining Less variable depending on body class -
i'd define global less variable depending on class applied <body>.
is possible less?
here mixin:
.dynamic-colors(@color) { //set variable @c-dynamic: @color; //i can use variable here .something { color: @c-dynamic; } } body.colors--black { .dynamic-colors(#000000); } body.colors--red { .dynamic-colors(#ff0000); } .something-else { //this returns undefined because @c-dynamic //was defined inside of .dynamic-colors() color: @c-dynamic; } i believe @c-dynamic limited scope of .dynamic-colors mixin.
is there way can set variable global?
so not leave 1 without answer. can define global variable mixin invoking mixin in global scope, e.g.:
.dynamic-colors(@color) { @c-dynamic: @color; } .dynamic-colors(#123); // expose @c-dynamic global scope div { color: @c-dynamic; // -> #123 } but (as mentioned in comments above) not mean in end. can't make (or other) variable value depend on body class since @ time of compilation less has no knowledge of html you're going apply generated css to.
Comments
Post a Comment