我已经定义了一些颜色:
$blue_1 : #ecf5f9;
$blue_2 : #cfe5ef;
$blue_3 : #b1d5e6;
现在我想为每个颜色自动创建。blue_{number}类。目前我得到:
@for $i from 1 through 12{
.blue_#{$i}{
color: $blue_#{$i};
}
}
但是' color:$blue_#{$i} '不起作用。我如何以另一种方式引用变量?!我困。
你可以这样做
函数nth的源代码
SCSS
$colors : #ecf5f9 #cfe5ef #b1d5e6;
@for $i from 1 through 3 {
h1.blue-#{$i}
{
background-color : nth($colors, $i)
}
}