Is there a way to dynamically pick between the two colors below based on a class on the body without adding the body class to every less snippet that contains the color using less?
@basketballColor: #ff9900;
@footballColor: #99743d;
Can we do this?
.navbar-inner {
background-color: @mainColor;
}
I know we can do this but would like to condense it
body.basketball {
.navbar-inner {
background-color: @basketballColor;
}
}
body.football {
.navbar-inner {
background-color: @footballColor;
}
}
This is quite often asked here at SO:
Just condense it via mixins, it is as simple as:
// usage:
body {
.navbar(basketball, #ff9900);
.navbar(football, #99743d);
}
// impl:
.navbar(@name, @color) {
&.@{name} .navbar-inner {
background-color: @color;
}
}
Or alternatively:
// usage:
.navbar(basketball, #ff9900);
.navbar(football, #99743d);
// impl:
.navbar(@name, @color) {
body.@{name} .navbar-inner {
background-color: @color;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With