Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sass 是否可以将mixin的结果存储在变量中?_Sass_Mixins - Fatal编程技术网

Sass 是否可以将mixin的结果存储在变量中?

Sass 是否可以将mixin的结果存储在变量中?,sass,mixins,Sass,Mixins,我已经创建了一个名为“我的梯度”的mixin @mixin my-gradient($outerColor, $centerColor) { background: $outerColor; /* Old browsers */ background: -moz-linear-gradient(left, $outerColor 0%, $centerColor 50%, $outerColor 100%); /* FF3.6+ */ background: -webk

我已经创建了一个名为“我的梯度”的mixin

@mixin my-gradient($outerColor, $centerColor) {
    background: $outerColor; /* Old browsers */
    background: -moz-linear-gradient(left,  $outerColor 0%, $centerColor 50%, $outerColor 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,$outerColor), color-stop(50%,$centerColor), color-stop(100%,$outerColor)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(left,  $outerColor 0%,$centerColor 50%,$outerColor 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(left,  $outerColor 0%,$centerColor 50%,$outerColor 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(left,  $outerColor 0%,$centerColor 50%,$outerColor 100%); /* IE10+ */
    background: linear-gradient(to right,  $outerColor 0%,$centerColor 50%,$outerColor 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$outerColor', endColorstr='$outerColor',GradientType=1 ); /* IE6-9 */
}
我可以从css声明中的\u structure.scss文件中很好地使用它-例如

.top-bar-section li:not(.has-form) a:not(.button):hover {
    @include my-gradient($topbar-bg-color, scale-color($topbar-bg-color, $lightness: 50%));
}
但是是否可以将其包含在我的\u settings.scss文件中。有点像

$body-bg: my-gradient(#fff, #eee);

…但是一些有效的东西???

混合和功能是不能互换的。mixin不返回值,并且不能将其结果存储在变量中,只有函数可以这样做

如果您只想将mixin的参数存储为可在其他地方重用的变量,那么在调用mixin时可以使用(
)语法:

$body-bg: #fff, #eee; // list of arguments in the exact order they should be sent to the mixin

.foo {
    @include my-gradient($body-bg...);
}

混音和函数是不能互换的。mixin不返回值,并且不能将其结果存储在变量中,只有函数可以这样做

如果您只想将mixin的参数存储为可在其他地方重用的变量,那么在调用mixin时可以使用(
)语法:

$body-bg: #fff, #eee; // list of arguments in the exact order they should be sent to the mixin

.foo {
    @include my-gradient($body-bg...);
}
…您没有包括混音,而是尝试使用一个不存在的函数(因为您定义了一个,而不是一个)

这里的关键是:

  • 注意你在哪里定义了你的混音
  • 在您的预期用途之前,确保mixin定义为
  • 如果您的定义与您使用的文件不同(我想是的,我怀疑您没有在_settings.scss中定义它),请确保在导入_settings.scss之前导入带有mixin定义的文件
然后在示例中使用它:

.top-bar-section li:not(.has-form) a:not(.button):hover { @include my-gradient($topbar-bg-color, scale-color($topbar-bg-color, $lightness: 50%)); }
然而,正如另一条注释所述,mixin不会返回值,所以不能将它们存储在变量中

相反,您可以使用:

这相当于一个变量,您可以
@扩展该占位符任意次数(编译的CSS中没有重复的代码,而不是使用
@include
重复次数)

…您没有包括混音,而是尝试使用一个不存在的函数(因为您定义了一个,而不是一个)

这里的关键是:

  • 注意你在哪里定义了你的混音
  • 在您的预期用途之前,确保mixin定义为
  • 如果您的定义与您使用的文件不同(我想是的,我怀疑您没有在_settings.scss中定义它),请确保在导入_settings.scss之前导入带有mixin定义的文件
然后在示例中使用它:

.top-bar-section li:not(.has-form) a:not(.button):hover { @include my-gradient($topbar-bg-color, scale-color($topbar-bg-color, $lightness: 50%)); }
然而,正如另一条注释所述,mixin不会返回值,所以不能将它们存储在变量中

相反,您可以使用:


这相当于一个变量,您可以
@扩展该占位符任意多次(在编译的CSS中没有重复的代码,而不是使用
@include
重复多次)

您确实理解什么是mixin,对吗?它不返回值。我想知道是否有一些函数内置到基础中,可以在MyStays.SCSS中使用MIXIN。看起来不是。问题不在于文件,而在于你打算如何使用mixin。你知道什么是mixin,对吗?它不返回值。我想知道是否有一些函数内置到基础中,可以在MyStays.SCSS中使用MIXIN。看起来不是。问题不在于文件,而是你打算如何使用mixin。