You cannot assign a mixin result to a variable in LESS. You can use pattern matching to get essentially the same result with nearly the same amount of code:
.myGradient(gradient1) {
#gradient > .vertical(@black, @white);
}
@headerBackground: gradient1;
@footerBackground: gradient1;
header { .myGradient(@headerBackground); width: 100%; }
footer { .myGradient(@footerBackground); padding: 20px; }
Essentially, .myGradient(gradient1)
becomes your "variable" name that generates the same code no matter where you put it. Then you can control your gradients through the variables that you set that will match the pattern, so you could set up other gradients like so:
.myGradient(gradient2) {
#gradient > .vertical(@red, @blue);
}
.myGradient(gradient3) {
#gradient > .vertical(@yellow, @orange);
}
And then set various background variables to the gradient1
, gradient2
, gradient3
values, all using the .myGradient
mixin that will match to the pattern.