Making a Sass mixin with optional arguments

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

    Even DRYer way!

    @mixin box-shadow($args...) {
      @each $pre in -webkit-, -moz-, -ms-, -o- {
        #{$pre + box-shadow}: $args;
      } 
      #{box-shadow}: #{$args};
    }
    

    And now you can reuse your box-shadow even smarter:

    .myShadow {
      @include box-shadow(2px 2px 5px #555, inset 0 0 0);
    }
    

提交回复
热议问题