Set a variable in Sass depending on the selector

前端 未结 8 1121
失恋的感觉
失恋的感觉 2020-12-10 10:20

I’ve got a website that’s using a few different ‘main’ colors. The general HTML layout stays the same, only the colors change depending on the content.

I was wonderi

8条回答
  •  无人及你
    2020-12-10 10:40

    If you don't want to use a variable for each color, you can use one variable for all kinds of colors. In the mixin you can choose the right color with nth. For instance, if you write the index of the color as 1, then you get the first color in the color variable.

    $colors: #444, #555, #666, #777;
    
    @mixin content($color-default-num, $color-main-num) {
      background: nth($colors, $color-default-num);
      color: nth($colors, $color-main-num);
    }
    
    body.class-1 {
      @include content(1, 2);
    }
    

提交回复
热议问题