react中修改antd的默认样式

最近在做react+antd项目。不可避免的遇到了修改antd默认样式的问题。

比如,table组件的表头背景色设置,如果直接使用元素样式,会修改整个项目的table。这里我用的方法是,给table添加一个div父元素,给他设置个className,然后设置这个样式内的table表头样式。

我使用的.less预编译。

              <div className={styles.boxW} >
                    <Table 
                      columns={colType}
                      rowKey='fxwd'
                      pagination={false}
                      bordered
                      dataSource={dataType}
                    />
              </div>
.boxW,.normalB {
    :global {
        .ant-table-thead > tr > th, .ant-table-tbody > tr > td {
            padding: 8px 8px !important;
        }
        .ant-table-thead > tr > th {
            background-color: rgb(192, 244, 248);
        }
        .ant-table-thead > tr > th:hover {
            background-color: rgb(192, 244, 248);
        }
        .ant-table-thead > tr > th.ant-table-column-has-actions.ant-table-column-has-sorters:hover {
            background: rgb(192, 244, 248);
        }
    }
}

这样就可以只修改到当前文件里table的样式了。

这里顺便记录一下.less的样式继承,通过(&:extend(被继承class名))。

.boxW {
    min-width: 1150px;
}

.normalB {
    &:extend(.boxW);
    &:extend(.boxBorder);

}

 

转载于:https://www.cnblogs.com/thhj-IT/p/10797175.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值