Is it possible to set a color based on the lightness/darkness of a less variable?
Currently I have the following code:
li {
color: darken(@bodyBackground, 10%);
}
This works providing @bodyBackground
is a light color. However if it was a dark color I'd like to use lighten(@bodyBackground, 10%)
. Is this possible with LESS?
You can be much smarter than this. You can make a mixin to check the provided color, and perform either a darken or lighten depending on its color:
Here is an example mixin, that takes the background color as the variable, and works out what text color to use. Returning either a light or dark output.
http://codepen.io/TristanBrotherton/pen/GwIgx?editors=110
There's
contrast
function, e.g.: