我正在尝试在我的变量上使用字符串插值来引用另一个变量:
// Set up variable and mixin
$foo-baz: 20px;
@mixin do-this($bar) {
width: $foo-#{$bar};
}
// Use mixin by passing 'baz' string as a param for use $foo-baz variable in the mixin
@include do-this('baz');
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我收到以下错误:
未定义的变量:"$ foo-".
Sass是否支持PHP风格的变量变量?
是否可以在 Sass 中用另一个变量引用一个变量?我想做这样的事情:
$gray = #ccc;
$white = #fff;
@each $color in gray, white {
div_#{$color} { // works fine
color: #{$#{$color}}; // fails
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了所有我能想到的变化来使插值工作并且没有骰子。有谁知道这是否可能?谢谢!