There is a little SASS to LESS convergence here... Does anyone know what is the correct syntax for these? The code below is the pure SASS mixins I used to use. Thanks for helping
@mixin linear-gradient($left, $right, $optional:false) {
@if $optional and type_of($optional) == number {
background: -webkit-linear-gradient($optional + deg, $left, $right);
background: -o-linear-gradient($optional + deg, $left, $right);
background: -moz-linear-gradient($optional + deg, $left, $right);
background: linear-gradient($optional + deg, $left, $right);
} @else {
@if $optional == "right" {
background: -webkit-linear-gradient(left, $left, $right);
background: -o-linear-gradient(left, $left, $right);
background: -moz-linear-gradient(left, $left, $right);
background: linear-gradient(to right, $left, $right);
} @if $optional == "left" {
background: -webkit-linear-gradient(right, $left, $right);
background: -o-linear-gradient(right, $left, $right);
background: -moz-linear-gradient(right, $left, $right);
background: linear-gradient(to left, $left, $right);
} @else { // top to bottom
background: -webkit-linear-gradient($right, $left);
background: -o-linear-gradient($right, $left);
background: -moz-linear-gradient($right, $left);
background: linear-gradient($right, $left);
}
}
}
Less uses guarded mixins with
when
conditions to mimick theif/else
logic. You can convert that SASS mixin to its Less equivalent like shown below. Most of the code is self explanatory (provided you have basic understanding of how Less works). I have also added some comments inline to make it clearer.and invoke it like (ignore the values for first two params, just dummy)
The compiled output would be
Note: As mentioned in comments, it is always better to use the built in
unit
function or the math operation to convert a plain number into degrees (or anything like px, em etc) instead of using the string concatenation method. The following are samples on how to do it.Using
unit
function:Using math operation: