我希望能够得到一个确定的答案,是否可以根据另一个变量的值来引用变量。在PHP(和其他语言)中,这是可能的。
例如(在Sass中):
我想将边框颜色设置为$green(或$blue、$yellow等),这些变量被包含在局部文件中。我正在循环遍历颜色名称列表如下:
$colors = green, yellow, blue;
@each $c in $colors {
&.#{$c} {
border-color: $#{$c};
}
}
以上代码(理论上)会生成.green、.yellow和.blue类,每个类的边框颜色分别设置为$green、$yellow或$blue。
很显然,以上代码不起作用,但在Sass/Compass中有另一种实现方法吗?