Making a Sass mixin with optional arguments

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

    With sass@3.4.9 :

    // declare
    @mixin button( $bgcolor:blue ){
        background:$bgcolor;
    }
    

    and use without value, button will be blue

    //use
    .my_button{
        @include button();
    }
    

    and with value, button will be red

    //use
    .my_button{
        @include button( red );
    }
    

    works with hexa too

提交回复
热议问题