【问题标题】:SASS mixins - default value for @contentSASS mixins - @content 的默认值
【发布时间】:2021-12-30 20:44:55
【问题描述】:

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

例如:

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

【问题讨论】:

    标签: sass scss-mixins


    【解决方案1】:

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

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

    @mixin foo {
      color: red;
      @content;
    }
    
    @mixin empty-foo {
      @include foo {
        width: 100%;
      }
    }
    
    .foo {
      @include foo {
        border: 1px solid;
      }
    }
    
    .bar {
      @include empty-foo;
    }
    

    【讨论】:

      【解决方案2】:

      试试这个:

      @mixin foo($content: 100%) {
          width:$content;
      }
      

      或者这个:

          @mixin foo() {
              $content: 100%;
              width:$content;
          }
      

      【讨论】:

      • 对不起,我不是这个意思
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      相关资源
      最近更新 更多