SASS - get map item value by item index
Asked Answered
S

1

7

I want to be able to pick a SASS map item value by that map item's index.
Simplified scenario:

SCSS

// Colors map (MUST stay this way due to system dependence)
$colors: (
    a: red,
    b: green,
    c: blue
);

@for $i from 1 through 3{
    a:nth-child({$i}){ color:[GET COLOR BY $i FROM $COLORS]; }
}

Is that possible?

Schofield answered 7/11, 2016 at 15:4 Comment(0)
S
13

gist demo

$colors: (
    a: red,
    b: green,
    c: blue
);

@each $color, $name in $colors{
  $i: index($colors, $color $name);
  a:nth-child(#{$i}){ color:$color; }
}
Schofield answered 7/11, 2016 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.