Making a Sass mixin with optional arguments

前端 未结 13 1363
眼角桃花
眼角桃花 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:12

    Old question, I know, but I think this is still relevant. Arguably, a clearer way of doing this is to use the unquote() function (which SASS has had since version 3.0.0):

    @mixin box-shadow($top, $left, $blur, $color, $inset:"") {
      -webkit-box-shadow: $top $left $blur $color unquote($inset);
      -moz-box-shadow: $top $left $blur $color unquote($inset);
      box-shadow: $top $left $blur $color unquote($inset);
    }
    

    This is roughly equivalent to Josh's answer, but I think the explicitly named function is less obfuscated than the string interpolation syntax.

提交回复
热议问题