Issue
I'm trying to have an array inside an object's value.
$background-things: (
'a': ['100vh', 'transparent', 'column'],
'higher': ['70vh', '#000', 'column'],
'lower': ['30vh', '#fff', 'row'],
);
and then later call them like this:
@each $name, $value in $background-things {
#background {
&-#{$name}: {
@include column($height:$value[0], $background-color:$value[1], $flex-direction:$value[2]);
}
}
}
This doesn't work. Is there any way to do this? On a side note, does the value $name work, because in the object's property I put '&-a'.
Solution
It is possible. @each part needs some modification:
&-#{$name}:should convert to&-#{$name}.- Access to list (array) items is possible with
nthfunction; for examplenth($value, 1). - lists indexes start from 1.
- Also
'100vh'doesn't need'.
More information about lists: https://sass-lang.com/documentation/modules/list
@each $name, $value in $background-things {
#background {
&-#{$name} {
@include column($height:nth($value, 1), $background-color:nth($value, 2), $flex-direction:nth($value, 3));
}
}
}
Answered By - Amirreza Noori
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.