Sass @each with multiple variables

前端 未结 5 1697
生来不讨喜
生来不讨喜 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:36

    I'm in the same boat (beginner to Sass/Compass) and had to do something similar. Here's what I came up with, using nested lists:

    $flash_types: (success #d4ffd4) (error #ffd5d1);
    
    @each $flash_def in $flash_types {
        $type: nth($flash_def, 1);
        $colour: nth($flash_def, 2);
    
        &.#{$type} {
            background-color: $colour;
            background-image: url(../images/#{$type}.png);
        }
    }
    

    It's not the most elegant solution but it should work if you can't find anything else. Hope it helps! I'd appreciate a better method too :)

提交回复
热议问题