请问要如何才能对一个antd组件的多个class做样式修改呢,使用多className覆盖不能做到?-灵析社区

CO_co

现在有一个需求,就是对antd的Collapse做一个样式的修改,去掉border-radius: // TestComp/index.tsx import type { CollapseProps } from 'antd'; import { Collapse, Button } from 'antd'; import styles from './index.module.css' const text = ` A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world. `; const items: CollapseProps['items'] = [ { key: '1', label: This is panel header 1, children: {text}, }, { key: '2', label: 'This is panel header 2', children: {text}, }, { key: '3', label: 'This is panel header 3', children: {text}, }, ]; const TestComp: React.FC = () => { const onChange = (key: string | string[]) => { console.log(key); }; return ; }; export default TestComp; css代码如下: // TestComp/index.module.tsx .myCollapse:global(.ant-collapse) { border-radius: 0px !important; } /* .myCollapse2:global(.ant-collapse-item:last-child) { border-radius: 0px !important; } */ 效果: 我们可以看到顶部左右是已经去除,但是下面的最后一个item没有去除: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/4ccfe00c4fe605291081e895758a9e6c.png) 所以我进一步想要对`.ant-collapse-item:last-child` 做修改: // TestComp/index.module.tsx .myCollapse:global(.ant-collapse) { border-radius: 0px !important; } .myCollapse2:global(.ant-collapse-item:last-child) { border-radius: 0px !important; } // tsx ; 但是不生效: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/83bc816506f5a01459727be06c4bf7d5.png) === 请问要如何才能对一个antd组件的多个class做样式修改呢? === ###### 编辑-01 代码如下: [https://codesandbox.io/s/ynk3tr](https://link.segmentfault.com/?enc=9MBtT68dacU8t3KV8CXDYA%3D%3D.3K7pENa0JsmYnVgSfyxDPGH%2BKt79DM36TItlN0SCxWc%3D)

阅读量:391

点赞量:15

问AI
首先你这元素就没找对位置啊,从你截图里来看圆角是里面的 ".ant-collapse-header" 的,你给 ".ant-collapse-item" 去圆角干啥? 其次为啥你要起俩 class 呢?都用一个不就好了……