css - 如何导入没有默认类名的 Ant Design 组件?

标签 css reactjs antd

我正在使用 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/

相关文章:

css - React/Material UI - <CardHeader> css

reactjs - 更改 "Select"的箭头图标

javascript - 基于其他Select字段选择ant design更新Select Option列表

css - Ant Design Tab Pane 最小高度 100%

html - 整个页面上的标签切换复选标记

html - -webkit 或 -moz 或任何真正必要的属性吗?

css - 通过 css 的 Vaadin Flow/10/11 样式组件

javascript - 使用 Javascript 的 CSS 剪辑路径动画

javascript - 如何在同一组件中使用 React useContext 来显示上下文中的数据

reactjs - 使用 React 显示隐藏多个元素