Sass 使用数组值作为变量

Sass 使用数组值作为变量,sass,Sass,假设我有这些颜色: $everlastingGreeN: #232553; $vividRed: #3435454; // and many more //and define those: $colors: (everlastingGreeN, vividRed); 如何迭代这些值,以便使用颜色名称作为类名,然后使用值作为背景色 @each $colors in $colors{ &.#{$colors} { background: {color value}

假设我有这些颜色:

$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%);
        }
    }
}

你要找的是一个列表

$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%);
        }
    }
}