connexo
connexo

Reputation: 56754

How to use "currentColor" CSS 3 keyword in LESS?

There is this new keyword in CSS 3 called currentColor which, as the name easily suggests, refers to the element's current color value.

Now I would like to use this keyword in LESS' darken(@color,@percentage)-function. The following throws an error in LESS compiling:

h1 {
    color: red;
    background-color: darken(currentColor, 75%);
}

The errormessage:

undefined_methodError: error evaluating function `darken`: 
Object [object Object] has no method 'toHSL'

Please ignore the fact that this is not yet supported in all browsers. Anyone know how to make this work in LESS?

Upvotes: 1

Views: 1111

Answers (1)

SLaks
SLaks

Reputation: 887415

It is fundamentally impossible to do that.

LESS compiles to regular CSS.
Any behavior that cannot be expressed in CSS also cannot be expressed in LESS.

In particular, the LESS darken() function works by changing the color at compile-time.
Since currentColor isn't known until runtime, you can't do that.

Upvotes: 8

Related Questions