通用sass样式汇总

// 当超过宽度时,显示省略号
@mixin ell() {
  overflow: hidden;
  -ms-text-overflow: ellipsis;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
// 利用绝对定位后margin自适应实现水平垂直居中,兼容IE6+
@mixin caa($direction: both) {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  @if $direction == both {
    margin: auto;
  } @else if $direction == h {
    margin-left: auto;
    margin-right: auto;
  } @else if $direction == v {
    margin-top: auto;
    margin-bottom: auto;
  }
}
// 只适用行内或行内块级元素水平垂直居中
@mixin ctv() {
  text-align: center;
  display: table-cell;
  vertical-align: middle;
}

// 尺寸确定,绝对定位后margin偏移实现水平垂直居中,兼容IE6+,不好用
@mixin ca($x, $y) {
  position: absolute;
  left: 50%;
  top: 50%;
  width: $x;
  height: $y;
  margin-left: -$x/2;
  margin-top: -$y/2;
}

// 利用translate实现未知宽高的水平垂直居中,兼容性不好
@mixin ct($direction: both) {
  position: absolute;
  @if $direction == both {
    top: 50%;
    left: 50%;
    -webkit-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
  } @else if $direction == h {
    left: 50%;
    -webkit-transform: translate3d(-50%, 0, 0);
    transform: translate3d(-50%, 0, 0);
  } @else if $direction == v {
    top: 50%;
    -webkit-transform: translate3d(0, -50%, 0);
    transform: translate3d(0, -50%, 0);
  }
}

// flex实现水平垂直居中
@mixin cf($direction: both) {
  display: flex; /*谷歌,火狐等新版本*/
  display: -webkit-box; /*安卓低版本*/
  display: -moz-box; /*火狐低版本*/
  display: -ms-flexbox; /*IE版本*/
  display: -webkit-flex; /*谷歌*/
  @if $direction == both {
    justify-content: center;
    -webkit-box-pack: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    align-items: center;
    -webkit-box-align: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
  } @else if $direction == h {
    justify-content: center;
    -webkit-box-pack: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
  } @else if $direction == v {
    align-items: center;
    -webkit-box-align: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
  }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风里有诗句哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值