user2371684 user2371684 - 16 days ago 5
Sass (Sass) Question

sass mixin for linear-gradient, code explanation

I found the following mixin on the web, but have forgotten where I found it.

@mixin linear-gradient($direction, $gradients...) {
background-color: nth($gradients, 1);
background-image: linear-gradient($direction, $gradients...);
}


and then be called upon in a class with:

.selector {
@include linear-gradient(to right, magenta, red, orange, yellow, green, blue, purple);
}


This works fine, my question is about the
background-color: nth($gradients, 1);
is this a index that starts with 1 and is it used as a color-start?
Can someone explain?

Thanks :)

Answer

Yes,nth(gradients,1) picks the first element from the gradients list

so it would background-color:magenta here

for more explanation this

Comments