有没有办法将外部变量导入mixins?
我想从mixin参数生成一个variablename
然后从外部源调用它.这有意义吗?
variables.scss
/* Striped status bar variables ******************************************/
$greyFirstGradientStartColor: #999999;
$greyFirstGradientEndColor: #d3cfcf;
$greySecondGradientStartColor: #ababab;
$greySecondGradientEndColor: #595959;
mixins.scss
@import variables.scss
[...]
@mixin gradient-repeating($color, $deg, $firstWidth, $space, $secondWidth){
background-image:
repeating-linear-gradient(
$deg,
$(#{$color}FirstGradientStartColor),
$(#{$color}FirstGradientEndColor) $firstWidth+px,
$(#{$color}SecondGradientStartColor) ($firstWidth+$space)+px,
$(#{$color}SecondGradientStartColor) $secondWidth+px
);
}
我 – 主 – CSS-file.scss
@import variables.scss;
@import mixins.scss;
[...]
@include gradient-repeating(grey, -45, 20, 0, 20);
最佳答案 不可以.Sas中不存在变量变量.通常使用列表或列表列表.
你的mixin可以写成这样:
$grey-gradient: #999999 #d3cfcf, #ababab #595959;
@mixin gradient-repeating($color, $deg, $firstWidth, $space, $secondWidth){
$firstColor: nth($color, 1);
$secondColor: nth($color, 2);
background-image:
repeating-linear-gradient(
$deg,
nth($firstColor, 1),
nth($firstColor, 2) $firstWidth+px,
nth($secondColor, 1) ($firstWidth+$space)+px,
nth($secondColor, 1) $secondWidth+px
);
}
.foo {
@include gradient-repeating($grey-gradient, -45, 20, 0, 20);
}