Answer the question
In order to leave comments, you need to log in
How to correctly pass a variable to a mixin (SCSS)?
Greetings!
I'm trying to implement a certain mixin
one that will do all the template work, and all I have to do is pass the necessary constructions into it in the form of classes and their properties.
What should be the output:
.test-1 {
color: red;
}
.test-2 {
color: red;
}
.test-3 {
color: red;
}
@mixin get() {
@for $i from 1 through 3 {
@content;
}
}
@include get() {
.test-#{$i} {
color: red;
}
}
$i
doesn't exist yet, and I'm trying to pass it to mixin
. I understand the mistake, but how then to solve the problem with the assignment $i
at the end of the class name test
inside the body mixin get
? Answer the question
In order to leave comments, you need to log in
Content blocks passed to a mixin are evaluated in the same scope where the block is defined, not the mixin. This means that the mixin's local variables cannot be used in the passed content block and the variables will be treated as global - source .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question