Answer the question
In order to leave comments, you need to log in
Iterating over an array (sass/scss)?
Greetings!
I can't understand a few points in iterating arrays in scss
:
1. How to get the number of an array cell in a loop? For example, if we are now in item3
, then the number should be 3...
2. How to get the name of the cell in the loop ( item3
for example)?
3. How to get the contents of a cell in a loop ( red
for example)?
4. How would you iterate over such an array?
Thank you!
$colors: (
item1: green,
item2: orange,
item3: red,
item4: blue,
item5: lime
);
// визуально накидал цикл, чтобы было более нагляднее то, что я хочу узнать...
@for $i from 1 through length($colors)
{
.test-#{$number-array}-#{$name-array}
{
color: #{$value-array};
}
}
Answer the question
In order to leave comments, you need to log in
$colors: (
item1: green,
item2: orange,
item3: red,
item4: blue,
item5: lime,
);
.test {
@each $key, $color in $colors {
$index: index($colors, ($key $color));
&-#{$index}-#{$key} {
color: $color;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question