SASS -通过项目索引获取地图项目值



我希望能够根据该地图项的索引选择SASS地图项值。
简化的场景:

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]; }
}

这可能吗?

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; }
}

最新更新