覆盖 Antd 选择的 Item 颜色

编程入门 行业动态 更新时间:2024-10-11 23:24:53
本文介绍了覆盖 Antd 选择的 Item 颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想覆盖 ant-menu-item-selected 类的 background-color 属性.默认情况下它显示为蓝色.

I want to override the background-color property of the ant-menu-item-selected class. By default it appears blue.

import { Menu } from 'antd';
const { Item } = Menu;

//item2 will be rendered with the class 'ant-menu-item-selected'
const MyComp = () => (
  <Menu theme="dark" defaultSelectedKeys={["item2"]} mode="horizontal">
    <Item key="item1">Item 1</Item>
    <Item key="item2">Item 2</Item>
  </Menu>
);

ReactDOM.render(<MyComp />,document.getElementById('root'));

我该怎么办?

感谢您的帮助.

推荐答案

我发现我需要以更高的优先级覆盖 Ant Design 的属性.首先,我在每个 Item 元素上定义了一个 CSS 类:

I figured out that I needed to override Ant Design's properties with a higher priority. First, I defined a CSS class on each of my Item elements:

<Item key="item1" className="customclass">Item 1</Item>

然后我添加了 CSS:

Then I added the CSS:

.ant-menu.ant-menu-dark .ant-menu-item-selected.customclass {
  background-color: green; /*Overriden property*/
}

customclass 之前的第一部分是为了获得与 Ant Design 属性相同的优先级.customclass 类只是增加了超越 Ant Design 所需的一点优先级.

The first part before customclass is there to get the same priority than the properties of Ant Design. The class customclass just adds the little bit of priority needed to surpass that of Ant Design.

这篇关于覆盖 Antd 选择的 Item 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-20 08:55:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/980044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   Antd   Item

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!