scss循环如何同时使用两个数组?

$color: #ff0000 #ffa500 #008000;
$name: red yellow green;

如何用@each 或者@for 输出成这样。

.red{background: #ff0000;}
.yellow{background: #ffa500;}
.green{background: #008000;}
阅读 2.8k
1 个回答
$name: red yellow green;
$color: #ff0000 #ffa500 #008000;
@for $i from 1 to length($name) + 1 {
    @debug ".#{nth($name, $i)}{ background: #{nth($color, $i)} }";
}

图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进