less给table标签添加圆角边框

因为table的圆角实现比较复杂,所以写成一个less函数记录一下

使用

@import (reference) './utils.less';

table {
  // 给不同的顶点设置统一的圆角
  .add-radius-for-table(@border: 1px solid #000; @allRadius: 6px);
  // 可以给不同的顶点设置不同的圆角
  .add-radius-for-table(@border: 1px solid #000; @allRadius: 6px 7px 8px 9px);
}

工具函数 utils.less

/**
 * @description: 设置表格table的圆角边框
 * @param border: 表格的border样式:1px solid blue
 * @param allRadius: 表格的radius:5px 或 5px 10px 或 5px 10px 20px等
 */
.add-radius-for-table(@border, @allRadius) {
  .getFullStrFromNum(@allRadius);
  @leftTop: extract(@res, 1);
  @rightTop: extract(@res, 2);
  @rightBottom: extract(@res, 3);
  @leftBottom: extract(@res, 4);

  border-collapse: separate;
  border-spacing: 0px;

  tr {
    td, th {
      border: @border;
      border-top: none;
      border-left: none;
      &:first-child {
        border-left: @border;
      }
    }
    &:first-child {
      td, th {
        border-top: @border;
        &:first-child {
          border-top-left-radius: @leftTop;
        }

        &:last-child {
          border-top-right-radius: @rightTop;
        }
      }
    }

    &:last-child {
      td, th {
        &:first-child {
          border-bottom-left-radius: @leftBottom;
        }

        &:last-child {
          border-bottom-right-radius: @rightBottom;
        }
      }
    }
  }
}

/**
 * @description: 把 5px 10px 类型的数组参数补充到四位 5px 10px 5px 10px;为了方便后面统一取参
 * @param all: 5px 或 5px 10px 或 5px 10px 20px等
 */
.getFullStrFromNum(@all) {
  ._getFullStrFromNum(@all) {
    @res: @all;
  }
  ._getFullStrFromNum(@all) when (length(@all) = 1) {
    @res: @all @all @all @all;
  }
  ._getFullStrFromNum(@all) when (length(@all) = 2) {
    @res: extract(@all, 1) extract(@all, 2) extract(@all, 1) extract(@all, 2);
  }
  ._getFullStrFromNum(@all) when (length(@all) = 3) {
    @res: extract(@all, 1) extract(@all, 2) extract(@all, 3) extract(@all, 2);
  }
  ._getFullStrFromNum(@all);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值