• 【css】css优先级之 !important


    权重等级
    • 第一等:!important
    • 第二等:代表内联样式,如: style="",权值为1000。
    • 第三等:代表ID选择器,如:#content,权值为100。
    • 第四等:代表类,伪类和属性选择器,如 .content,权值为10。
    • 第五等:代表元素和伪元素选择器,如 h2:before:after,权值为1。
    • 第六等:通配选择器、选择符和逻辑组合伪类,权值为 0。
    例子

    react antd 覆盖组件库原有样式。

    <Collapse ghost>
      {onlineSubOrder.map((item) => {
        return (
          /* 在这里 */
          <Panel style={{color: 'blue'}} header={item.title} key={item.title}>
            <p>request : {item.context.request}</p>
            <p>response : {item.context.response}</p>
          </Panel>
        );
      })}
    </Collapse>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    style={{color: 'blue'}}会被放到 ant-collapse-item 类上面,而我们希望他应该被放到 ant-collapse-header,使得 header 文字显示为蓝色。

    在这里插入图片描述

    解决方法:

    // index.js
    import './index.css'
    <Collapse ghost>
      {onlineSubOrder.map((item) => {
        return (
          /* 在这里,设置类名,item.status 取值为 success/warn/faild */
          <Panel className={item.status} header={item.title} key={item.title}>
            <p>request : {item.context.request}</p>
            <p>response : {item.context.response}</p>
          </Panel>
        );
      })}
    </Collapse>
    
    
    // index.css
    .success .ant-collapse-header {
      color: #67c23a !important;
    }
    .warn .ant-collapse-header {
      color: #e6a23c !important;
    }
    .fail .ant-collapse-header {
      color: #f56c6c !important;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    如图所示,会强制使用 .success .ant-collapse-header 的样式。

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    Webpack 搭建 Vue + ts + tsx
    使用Dask,SBERT SPECTRE和Milvus构建自己的ARXIV论文相似性搜索引擎
    SpringCloud Alibaba(保姆级入门及操作)
    [100天算法】-搜索旋转排序数组(day 64)
    GraphQL
    螺杆支撑座的这些特点,你知道吗?
    浅谈制药企业安全供电系统的设计与应用
    【工具】转码silk格式为mp3
    ARM之栈与方法
    浅析linux异步io框架 io_uring
  • 原文地址:https://blog.csdn.net/weixin_43973415/article/details/126510060