代码之家  ›  专栏  ›  技术社区  ›  dom_ahdigital

使用sass在一系列颜色中循环[复制]

  •  1
  • dom_ahdigital  · 技术社区  · 7 年前

    我希望能够根据该映射项的索引选择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]; }
    }
    

    有可能吗?

    0 回复  |  直到 9 年前
        1
  •  4
  •   vsync    9 年前

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