0

有没有办法可以将其压缩得更多,所以我必须在这一行中添加:

background: linear-gradient(left, $rainbow-colors);

我需要在这里筑巢吗?

@mixin rainbow($colors...) {
    @each $color in $colors {
      .#{$color} {
            background: $color; } 
    }
  }
$rainbow-red: red;
$rainbow-orange: orange;
$rainbow-yellow: yellow;
$rainbow-green: green;
$rainbow-blue: blue;

body {
  background: -webkit-linear-gradient(left, $rainbow-red, $rainbow-orange, $rainbow-yellow, $rainbow-green, $rainbow-blue);
}
4

1 回答 1

1

您不必将每种颜色指定为其自己的变量。一个逗号分隔的列表就足够了。(此外,您的代码应该说to left,而不仅仅是left。)

body {
  $rainbow-colors: red, orange, yellow, green, blue;
  background: linear-gradient(to left, $rainbow-colors);
}
于 2018-05-30T14:13:31.770 回答