SASS mixins - @content 的默认值 [英] SASS mixins - default value for @content

查看:46
本文介绍了SASS mixins - @content 的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像使用参数一样为 @content 定义默认值?

Is it possible to define a default value for @content just as one would do with arguments?

例如:

@mixin foo {
    @content: width:100%;
}

推荐答案

不,@content 不是变量.您不能为其设置默认值.你无法操纵或检查它.

No, @content is not a variable. You cannot set a default value to it. You cannot manipulate or examine it.

如果 Alessandro 的答案不适合您的需求,您需要创建一个额外的 mixin 以获得您想要的结果:

If Alessandro's answer is unsuitable for your needs, you'll need to create an extra mixin to get the results you desire:

@mixin foo {
  color: red;
  @content;
}

@mixin empty-foo {
  @include foo {
    width: 100%;
  }
}

.foo {
  @include foo {
    border: 1px solid;
  }
}

.bar {
  @include empty-foo;
}

这篇关于SASS mixins - @content 的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆