假设我有这些颜色:
$everlastingGreeN: #232553;
$vividRed: #3435454;
// and many more
//and define those:
$colors: (everlastingGreeN, vividRed);
如何迭代这些值,以便我可以使用颜色名称作为类名,然后将值作为背景颜色?
@each $colors in $colors{
&.#{$colors} {
background: {color value};
&:hover {
background: darken({color value}, 10%);
}
}
}
答案 0 :(得分:3)
您要查找的是列表清单。
$everlastingGreeN: #232553;
$vividRed: #343545;
// and many more
//and define those:
$colors: everlastingGreeN $everlastingGreeN, vividRed $vividRed;
@each $color in $colors {
&.#{nth($color, 1)} {
background: nth($color, 2);
&:hover {
background: darken(nth($color, 2), 10%);
}
}
}