学习笔记--SASS编程基础(二)混合—mixin

混合  @mixin(迷信^_^)

sass 中可以通过@mixin 声明混合,它具有以下几方面特性:

        1、可以传递参数   

        2、参数名称以$开始,多个参数之间使用逗号分隔

        3、@mixin 的混合代码块由@include 来调用

、有参数混合:类似于函数的封装和调用

话不多说,上案例:

 sass编译:                                                             css 样式: 

@mixin opacity( $opacity : 50 ){                       |

            opacity : $opacity ;                                |

}                                                                         |

#imgBox{                                                           |    #imgBox{ 

            @include  opacity ;                               |               opacity : 50 ; 

}                                                                         |     }

#imgBox span{                                                  |   #imgBox span{  

            @include  opacity ( 90 ) ;                     |               opacity : 90  ;

}                                                                         |    }

二、多参数混合:

sass编译:

 @mixin box-specs($border : 1px dashed #ccc , $padding : 10px ){ 

                border-bottom : $border ;

                padding-top : $padding ;

                padding-bottom : $padding ;

}

.uls li{

                @include box-specs( 1px solid #ccc ) ;

}

.lis a{

                 @include box-specs( $padding : 15px  ) ;

}


css 样式:

.uls li{

                border-bottom : 1px solid #ccc ;

                padding-top : 10px ;

                padding-bottom : 10px ;

}

.lis a{

                border-bottom : 1px dashed #ccc ;

                padding-top : 15px ;

                padding-bottom : 15px ;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值