我有一个 mixin,它接受我想传递给变量的参数。
@mixin my_mixin($arg) {
background-color: $state-#{$arg}-text;
}
最佳答案
目前在 SASS 中无法对变量名进行插值。这是讨论此问题的问题 https://github.com/nex3/sass/issues/626
但是,您可以使用占位符的插值:
%my-dark-styles {
background-color: #000;
}
%my-white-styles {
background-color: #FFF;
}
@mixin my_mixin($arg) {
@extend %my-#{$arg}-styles;
}
.header {
@include my_mixin("dark");
}
.footer {
@include my_mixin("white");
}
这编译为:
.header {
background-color: #000; }
.footer {
background-color: #FFF; }
关于variables - 是否可以在 SASS 的变量中嵌套变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18501130/