【问题标题】:SASS/SCSS is there a way to merge a two 1D lists into a single 2D list?SASS/SCSS 有没有办法将两个 1D 列表合并为一个 2D 列表?
【发布时间】:2014-10-13 20:22:14
【问题描述】:

在 SCSS 中,我想合并以下列表:

$animals: dog, cat, rabbit, horse;
$colors: brown, orange, white, black;

变成这样:

$mylist: dog brown, cat orange, rabbit white, horse black;

这可能吗?然后我想像这样使用二维列表:

@each $animal, $color in $mylist {
   .my_#{$animal} {
     color: $color;
   }  
}

【问题讨论】:

    标签: list sass each


    【解决方案1】:

    您正在寻找的是zip() 函数:

    $animals: dog, cat, rabbit, horse;
    $colors: brown, orange, white, black;
    
    @each $animal, $color in zip($animals, $colors) {
       .my_#{$animal} {
         color: $color;
       }  
    }
    

    请注意,这是 Sass 3.3 的一项功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-12
      • 2021-03-30
      • 2013-12-14
      • 2017-12-11
      • 2014-01-27
      • 2018-11-25
      相关资源
      最近更新 更多