I have a page template which has a branding class on the body
element:
<body class="brand-africa">
<h1>Africa</h1>
</body>
Using the following Less, I can use a variable for the brand colour and apply it to the color
of a CSS selector:
@brand-default: #649d84;
@brand-africa: #df6f20;
@brand-nz: #444;
.brand-color {
.brand-default & {
color: @brand-default;
}
.brand-africa & {
color: @brand-africa;
}
.brand-nz & {
color: @brand-nz;
}
}
h1 {
.brand-color;
}
This works well, but sometimes I want to apply the color to another CSS declaration - such as background-color
, and to do this with the above code I'd need to duplicate the .brand-color
mixin to instead apply background-color
.
Ideally I'd like the mixin to return a variable - I know it's possible, but I can't work out how to use the classname to determine the returned value.
See Question&Answers more detail:os