简体   繁体   English

scss @each与颜色映射一起使用

[英]scss @each use with color map

$Black: rgba(0, 0 ,0, 0.87);

$Color: (
  black: $Black,
  white: $White,
  primary: $Primary,
  second: $Second,
  accent: $Accent
);

@each $get-color in $Color {
  .font-#{$get-color} {
    color: $get-color;
  }
}

Compile to 编译为

.font-black rgba(0, 0, 0, 0.87) {
  color: black rgba(0, 0, 0, 0.87)
}

Color codes are compile together. 颜色代码一起编译。 I hope it will be written as follows when it is converted. 我希望它将在转换时如下编写。

.font-black {
  color: rgba(0, 0, 0, 0.87)
}

You have to use 2 variables in your loop: one for key and one for your value. 您必须在循环中使用2个变量:一个用于键,另一个用于值。 So you could try this: 因此,您可以尝试以下操作:

$Black: rgba(0, 0 ,0, 0.87);

$Color: (
  black: $Black
);

@each $get-color, $value in $Color {
  .font-#{$get-color} {
    color: $value;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM