常用less函数

1,文本行数限制

.add-text-row-limit(@row) {
  overflow: hidden;
  text-overflow: ellipsis;
  .create();

  .create() when (@row > 1) {
    display: -webkit-box;
    -webkit-line-clamp: @row;
    -webkit-box-orient: vertical;
  }

  .create() when (@row = 1) {
    white-space: nowrap;
  }
}
1.1,使用
p {
  .add-text-row-limit(1);
}

2,三角箭头

.add-triangle-arrow(@position, @size, @bk-color, @arrow-direction: @position) {
  position: absolute;
  content: '';
  border: @size solid transparent;
  .create();

  // 上下
  .create() when (@position = top) {
    left: 50%;
    top: 0;
    transform: translate(-50%, -100%);
  }

  .create() when (@position = bottom) {
    left: 50%;
    bottom: 0;
    transform: translate(-50%, 100%);
  }

  .create() when (@arrow-direction = top) {
    border-bottom-color: @bk-color;
    border-top: 0;
  }

  .create() when (@arrow-direction = bottom) {
    border-top-color: @bk-color;
    border-bottom: 0;
  }

  // 左右
  .create() when (@position = left) {
    top: 50%;
    left: 0;
    transform: translate(-100%, -50%);
  }

  .create() when (@position = right) {
    top: 50%;
    right: 0;
    transform: translate(100%, -50%);
  }

  .create() when (@arrow-direction = left) {
    border-right-color: @bk-color;
    border-left: 0;
  }

  .create() when (@arrow-direction = right) {
    border-left-color: @bk-color;
    border-right: 0;
  }
}
2.1,使用:
div::after {
  .add-triangle-arrow(
    箭头的位置: left | right | bottom | top,
    箭头大小: 5px,
    箭头颜色: blue,
    箭头方向?: left | right | bottom | top,
  );
}

3,媒体查询

@pad-screen: 768px;
@iPad-pro-screen: 1024px;
@screenDeviation: 0.1;

.phone(@content) {
  @media screen and (max-width: (@pad-screen - @screenDeviation)) {
    @content();
  }
}

.phoneOrPad(@content) {
  @media screen and (max-width: @iPad-pro-screen) {
    @content();
  }
}

.ipad(@content) {
  @media screen and (min-width: @pad-screen) and (max-width: @iPad-pro-screen) {
    @content();
  }
}

.notIpad(@content) {
  @media screen and (max-width: (@pad-screen - @screenDeviation)), screen and (min-width: (@iPad-pro-screen + @screenDeviation)) {
    @content();
  }
}

.pcOrPad(@content) {
  @media screen and (min-width: @pad-screen) {
    @content();
  }
}

.pc(@content) {
  @media screen and (min-width: (@iPad-pro-screen + @screenDeviation)) {
    @content();
  }
}
3.1 使用
div {
  .phone({
    font-size: 15px;
  });
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值