I asked a similar question to this a while ago, and received a great answer. Unfortunately, this time round the answer is not sufficient, and the question is slightly more complex.
I am using LESS with the LESSHat mixins to build a theme at the moment. I have defined a number of colours as variables, and am currently trying to define a gradient using LESSHat's .gradient()
mixin. The problem is that the mixin accepts a string as a single argument, rather than a series of arguments for each gradient parameter, for example:
#element {
.gradient(~"linear-gradient(90deg, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%)");
}
All is well and good with the above, and I can use my variables inside the string using String Interpolation (i.e. @{color-var}
). However, I would also like to run some functions on the variables, something like this:
.gradient(~"linear-gradient(top, @{green} 0%, @{green} 50%, darken(@green, 10%) 50%, darken(@green, 10%) 100%)");
The problem is that darken(@green, 10%)
is never compiled, and some browsers simply interpret this color as green
. Does anyone know the correct way to include the return of the darken()
function inside the string above, without creating a separate variable for that?
For reference, I have tried the following to no avail:
.gradient(~"linear-gradient(top, @{green} 0%, @{green} 50%, "darken(@green, 10%)" 50%, "darken(@green, 10%)" 100%)");
.gradient(~"linear-gradient(top, @{green} 0%, @{green} 50%, {darken(@{green}, 10%)} 50%, {darken(@{green}, 10%)} 100%)");
This should work, it's like your first approach but you should also include the ~
:
.gradient(~"linear-gradient(top, @{green} 0%, @{green} 50%, " darken(@green, 10%) ~" 50%, " darken(@green, 10%) ~" 100%)");
Have you tried saving the darkened color into a variable first? Like this:
@darkened-green: darken(@green, 10%);
.gradient(~"linear-gradient(top, @{green} 0%, @{green} 50%, @{darkened-green} 50%, @{darkened-green} 100%)");
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