Sass @each with multiple variables

前端 未结 5 1681
生来不讨喜
生来不讨喜 2020-11-30 01:58

I\'m just getting started with Sass and Compass, and I\'m loving it. Something I\'d like to do is take advantage of the @each function to simplify repetitive ta

5条回答
  •  时光取名叫无心
    2020-11-30 02:47

    Another solution could be to create different lists and "zip" them.

    //Create lists
    $animals: puma, sea-slug, egret, salamander;
    $animals-color: black, green, brown, red;
    
    //Zip lists
    $zoo: zip($animals, $animals-color);
    
    //Do cycle
    @each $animal, $color in $zoo {
        .#{$animal}-icon {
            background-color: $color;
        }
    }
    

    Probably this solution is more complicated to mantain than the others, but if you use a list more than one time, you can save time. (was my case)

提交回复
热议问题