在sass中是否可能使混音器过载?

在sass中是否可能使混音器过载?,sass,Sass,假设你有这样一个阴影的混合: @mixin box-shadow($offset, $blur, $color) { -moz-box-shadow: $offset $offset $blur $color; -webkit-box-shadow: $offset $offset $blur $color; box-shadow: $offset $offset $blur $color; } 是否有可能使用以下内容使该mixin过载: @mixin box-shadow(

假设你有这样一个阴影的混合:

@mixin box-shadow($offset, $blur, $color)
{
   -moz-box-shadow: $offset $offset $blur $color;
   -webkit-box-shadow: $offset $offset $blur $color;
   box-shadow: $offset $offset $blur $color;
}
是否有可能使用以下内容使该mixin过载:

@mixin box-shadow($offset, $blur)
{
    @include box-shadow($offset, $blur, #999);
}

或者我必须为mixin使用不同的名称吗?

您不能过载,但典型的做法是设置默认值

/*这将把color作为arg,或者在2 arg调用中返回到#999*/
@混合框阴影($offset,$blur,$color:#999){
-webkit盒阴影:$offset$offset$blur$color;
-moz盒阴影:$offset$offset$blur$color;
框阴影:$offset$offset$blur$color;
}

如果您需要稍微调整供应商的混音,可以将其复制到另一个文件(包含在原始文件之后)并在其中编辑,供应商的原始文件将被忽略

@import "_their-mixins";
@import "_our-mixins";

警告-这可能取决于您使用的处理器。在撰写本文时,使用numbers1311407解决方案非常有效,但您可以使用该指令创建较短的混音:

@mixin box-shadow($offset, $blur, $color: #999) {
  @each $prefix in -moz-, -webkit-, null {
    #{$prefix}box-shadow: $offset $offset $blur $color;
  }
}

甜蜜的。。。但这基本上是重载:)。@Tomas虽然在您的情况下有效,但这根本不是重载:重载将允许您在这个
边界半径($radius)中有两个单独的混音
边框半径($top corners,$bottom corners)
当现有mixin是供应商库的一部分而您不能或不想修改时,这也不能解释。@MatthewG这就是为什么我在这里只是作为提示,在sass中管理供应商前缀很困难,web浏览器不断更新,很难保证我们的代码在每次更新时都能正常运行,所以我建议使用是的,grunt做到了-gulp不要