1

假设我有这些颜色:

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

1 回答 1

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%);
        }
    }
}
于 2013-02-10T03:48:55.930 回答