【问题标题】:SASS - get map item value by item indexSASS - 通过项目索引获取地图项目值
【发布时间】:2016-11-07 23:32:58
【问题描述】:

我希望能够通过该地图项的索引选择一个 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]; }
}

这可能吗?

【问题讨论】:

    标签: sass


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多