scss使用for循环遍历,动态赋值类名并配置不同颜色

需求:后端要传入不同的等级,前端通过等级展示不同的字体颜色,通过scss遍历更有利于动态修改颜色或者增删等级

1.通过 @for $i from 1 through 4 定义循环,索引值为i
2.nth($colors, $i) 取出对应的颜色
$colors: #ff0000, #00ff00, #0000ff, #eeff00;
@for $i from 1 through 4 {
    .alarmDevice-#{$i}{
        color:nth($colors, $i);
    }
}

你可能感兴趣的:(scss)