pass a list to a mixin as a single argument with SASS

后端 未结 6 1035
悲哀的现实
悲哀的现实 2021-01-30 06:35

I like to make mixins with SASS that help me make good cross-browser compatibility. I want to make a mixin that looks like this:

@mixin box-shadow($value) {
             


        
6条回答
  •  后悔当初
    2021-01-30 07:13

    There's many ways to do this, the best way is using a mixin like so:

    @mixin box-shadow($value...) {
      -webkit-box-shadow: $value;               
      -moz-box-shadow: $value;                  
      box-shadow: $value;
    }
    

    And include it like this:

    @include box-shadow(inset 0 1px 0 #FFD265, 0 0 0 1px #912E01, 0 0 0 7px rgba(0, 0, 0, .1), 0 1px 4px rgba(0, 0, 0, .6));

    or

    @mixin box-shadow($value) {
          -webkit-box-shadow: #{$value};               
          -moz-box-shadow: #{$value};          
          box-shadow: #{$value};
    }
    

    And include it like this:

    @include box-shadow("inset 0 1px 0 #FFD265, 0 0 0 1px #912E01, 0 0 0 7px rgba(0, 0, 0, .1), 0 1px 4px rgba(0, 0, 0, .6)");
    

    or:

    @mixin box-shadow($value) {
          $value: unquote($value);
          -webkit-box-shadow: $value;               
          -moz-box-shadow: $value;          
          box-shadow: $value;
    }
    

    or:

    @mixin box-shadow($value) {
      -webkit-box-shadow: $value;               
      -moz-box-shadow: $value;                  
      box-shadow: $value;
    }
    

    And include it like this:

    @include box-shadow((inset 0 1px 0 #FFD265, 0 0 0 1px #912E01, 0 0 0 7px rgba(0, 0, 0, .1), 0 1px 4px rgba(0, 0, 0, .6)));
    

    Sass is very powerful :)

提交回复
热议问题