Making a Sass mixin with optional arguments

前端 未结 13 1238
眼角桃花
眼角桃花 2020-12-22 16:31

I am writing a mixin like this:

@mixin box-shadow($top, $left, $blur, $color, $inset:\"\") {
    -webkit-box-shadow:          


        
相关标签:
13条回答
  • 2020-12-22 17:27

    I know its not exactly the answer you were searching for but you could pass "null" as last argument when @include box-shadow mixin, like this @include box-shadow(12px, 14px, 2px, green, null); Now, if that argument is only one in that property than that property (and its (default) value) won't get compiled. If there are two or more args on that "line" only ones that you nulled won't get compiled (your case).

    CSS output is exactly as you wanted it, but you have to write your nulls :)

      @include box-shadow(12px, 14px, 2px, green, null);
    
      // compiles to ...
    
      -webkit-box-shadow: 12px 14px 2px green;  
      -moz-box-shadow: 12px 14px 2px green;  
      box-shadow: 12px 14px 2px green;
    
    0 讨论(0)
提交回复
热议问题