丁同亚的博客
夺朱非正色

下面一段代码是项目中全局样式的一段代码,解释下作用

/**定义一个变量 */
$me-button-bgcolor: (
  primary: $mybutton,
  warning:"#fff",
);
/**
*   @each 是一个Sass指令,用于循环遍历列表或映射。
    $key, $color in $me-button-bgcolor 表示将要遍历名为 $me-button-bgcolor 的映射(map),其中每次迭代时,$key 将代表当前项的键名,而 $color 将代表与该键关联的值。
    .me-button-#{$key} 使用了Sass中的插值语法 #{} 来动态生成类选择器的名字。这里的意思是,对于映射中的每个键,都会生成一个以.me-button-开头并接着键名的CSS类选择器。
    {background: $color !important;} 定义了这些生成的选择器内的样式规则
*/
@each $key,
$color in $me-button-bgcolor {
  .me-button-#{$key}{
    background: $color !important;
    border-color: $color !important;
    color:#FFFFFF !important;
    height: 32px !important;
    font-size: 14px !important;
    padding: 6px 12px !important;
  }
}

编译后的代码如下:

.me-button-primary {
  background: #007bff !important;
  border-color: #007bff !important;
  color: #FFFFFF !important;
  height: 32px !important;
  font-size: 14px !important;
  padding: 6px 12px !important;
}

.me-button-warning {
  background: #fff !important;
  border-color: #fff !important;
  color: #FFFFFF !important; 
  height: 32px !important;
  font-size: 14px !important;
  padding: 6px 12px !important;
}
posted on 2024-12-03 09:14  丁同亚的博客  阅读(10)  评论(0)    收藏  举报