sass - 公用方法封装

本文介绍了一组 Sass 混合宏的使用方法,包括设置宽高、行高、绝对定位等,帮助开发者更高效地完成 CSS 样式编写。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 设置宽高
@mixin wh($wid,$hei){
    @if $wid {
        width: $wid;
    }
    @if $hei {
        height: $hei;
    }
    overflow: hidden;
}
// 设置高度与行高一致
@mixin lineH($index){
    height: $index;
    line-height: $index;
}
// 父元素相对,子元素绝对
@mixin absolut($index){
    position: relative;
    &:after{
        content: "";
        position: absolute;
        z-index: $index;
    }
}
// 文本样式
@mixin txts($fs,$cl){
    @if $fs {
        font-size: $fs;
    }
    @if $cl {
        color: $cl;
    }
}
// 透明度设置
@mixin op($index){
    opacity: $index;
    filter: alpha(opacity = ($index * 100));
}
// 背景图
@mixin bgImg($link){
    background: url("../img/"+$link) no-repeat;
}
// icon图标
@mixin iCon($w,$h,$bg,$index){
    @include wh($w,$h)
    @include bgImg($bg)
    margin-right: $index;
}
// 变形
@mixin transForm($index){
    -webkit-transform: $index;
    -moz-transform: $index;
    -ms-transform: $index;
    transform: $index;
}
// 制作小箭头
@mixin arrow($clr,$index){
        border-right: 1px solid $clr;
        border-bottom: 1px solid $clr;
        @include transForm(rotate($index))
}
// 圆角度
@mixin radiu($index){
 -webkit-border-radius: $index;
 -moz-border-radius: $index;
 border-radius: $index;
}
// 盒阴影
@mixin boxSd($shadow...){
    -webkit-box-shadow: $shadow;
    -moz-box-shadow: $shadow;
    -ms-box-shadow: $shadow;
    box-shadow: $shadow;
}
// 常用内联块元素设置
%inlineB{
    display: inline-block;
    _display: inline;
}

 

转载于:https://www.cnblogs.com/padding1015/p/8663540.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值