0
基本上,我试图生成很多样式,每个样式都包含图像和颜色。列出颜色并且变量以相同的方式命名。问题是我不能让Sass使用动态生成的名字(靠近{color}。但是可以这样使用吗?谢谢!在列表中动态创建带有sass的变量
$color-style-winter: #11111;
$color-style-christmas: #22222;
$styles: 'winter' 'hills',
'christmas' 'xmas';
@each $name, $image in $styles {
.style-#{$name} {
background: url('../../images/styles/#{$image}.jpg');
}
a {
color: $color-style- + $name;
}
}
这是我做的第一个,但是编译器是不是就OK了:“未定义的变量:“$颜色风格 - “。' 我也尝试连接,但这不是使用变量值,只在变量名写入生成的CSS: 颜色:unquote('$ color-style-'+ $ name);生成: 颜色:$ color-style-christmas; –
http://krasimirtsonev.com/blog/article/SASS-interpolation-in-a-name-of-variable-nest-variables-within-variables – Michael
再次感谢,但这不符合我的预期。我将继续使用3条目列表,这是目前最简单的解决方案! –