是否可以在 sass 中重载混入? [英] Is it possible to overload mixins in sass?
本文介绍了是否可以在 sass 中重载混入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设你有一个像这样的 shadow 的 mixin:
Let say you have a mixin for shadow like such:
@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:
Is it possible to overload that mixin with something like:
@mixin box-shadow($offset, $blur)
{
@include box-shadow($offset, $blur, #999);
}
或者我必须为 mixin 使用不同的名称吗?
Or do I have to use different names for the mixins?
推荐答案
你不能重载,但典型的做法是设置默认值.
You can't overload, but the typical practice would be to set defaults.
/* this would take color as an arg, or fall back to #999 on a 2 arg call */
@mixin box-shadow($offset, $blur, $color: #999) {
-webkit-box-shadow: $offset $offset $blur $color;
-moz-box-shadow: $offset $offset $blur $color;
box-shadow: $offset $offset $blur $color;
}
这篇关于是否可以在 sass 中重载混入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文