SASS mixins - default value for @content

后端 未结 2 1257
南旧
南旧 2020-12-22 04:41

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

For instance something like:

@mixin foo {
            


        
相关标签:
2条回答
  • 2020-12-22 05:13

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

    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;
    }
    
    0 讨论(0)
  • 2020-12-22 05:27

    try this:

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

    or this:

        @mixin foo() {
            $content: 100%;
            width:$content;
        }
    
    0 讨论(0)
提交回复
热议问题