我正在使用 Ant Design在我的 react 元素中。我想使用没有默认类名的 Ant Design 组件。
注意以下代码:
import { Typography } from "antd";
const { Title } = Typography;
~~
<Title level={4}> ...
有以下原因:
<h4 class="ant-typography" ...
及其 CSS:
// in the less file:
h4.ant-typography {
// some css
}
所以当我将我的类名添加到组件时,Ant Design 组件的类名的优先级比我的高!
我的类(class)名称是 .root-23-07
。此优先级编号为 10
,但由于在较少文件中使用标签名称,And Design CSS 选择的优先级编号为 11
。所以 Ant Design 样式会覆盖我的样式。
我想在没有默认类名的情况下使用 And Design 的组件。 这可能吗?
最佳答案
如果我正确理解你的问题,不,你不能在没有底层类名的情况下使用 antd。因为 React 输出原始的 html 和 css,没有类名会导致在您提供的 css 之外没有任何样式。
你要么需要让你的类匹配特异性级别,要么使用 !important
关于css - 如何导入没有默认类名的 Ant Design 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58070076/