【问题标题】:Use array value as variable [duplicate]使用数组值作为变量[重复]
【发布时间】:2013-02-10 11:48:55
【问题描述】:

假设我有这些颜色:

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

【问题讨论】:

    标签: sass


    【解决方案1】:

    您要查找的是列表列表。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-29
      • 2013-02-03
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 2015-10-15
      • 2020-05-24
      • 2014-05-23
      相关资源
      最近更新 更多