每个循环是否可以在SASS中动态使用变量名? [英] Is it possible to use variable names dynamically in SASS each loop?
问题描述
这是一个简化的示例。我想做的是使用数组中的项目输出我先前创建的变量值。尝试通过连接 $来创建变量的以下语法显然是错误的,但是我正在使用它来明确说明我要执行的操作。
This is a simplified example. What I'd like to do is use the items in the array to output variable values I've previously created. The syntax below that tries create a variable by concatenating a '$' is obviously wrong but I'm using it to make it clear what I'm trying to do.
$puma-width: 100px;
$slug-width: 200px;
@each $animal in puma, slug {
.#{$animal}-title {
width: $+#{$animal}-width;
}
}
所需输出:
.puma-title {
width: 100px;
}
.slug-title {
width: 200px;
}
推荐答案
这就是我想要的SASS也是如此,但是在阅读了他们的讨论列表后,我得出结论,尚不支持这种变量插值。
That's something that I wanted in SASS as well, but after reading their discussion list, I concluded that this kind of variable interpolation is not supported yet.
我没有尝试Less,但是他们的文档建议使用@@语法是可行的。
I didn't try Less, but their documentation suggests it would be possible with @@ syntax.
这篇关于每个循环是否可以在SASS中动态使用变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!