SASS - 按项目索引获取地图项目

时间:2016-11-07 15:04:46

标签: 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]; }
}

这可能吗?

1 个答案:

答案 0 :(得分:4)

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; }
}
相关问题