首页 > 解决方案 > 如何禁用 ListItem 的一些 Material UI css

问题描述

我正在使用 Material-UI ListItem 组件,我想摆脱默认的背景颜色。我已经尝试过使用类,但我的值被这个覆盖了:

如何禁用此默认规则?

标签: reactjsmaterial-ui

解决方案


您可以全局覆盖任何 Material UI 组件的样式。

在您的应用程序中查找您调用的点createMuiTheme,然后像这样添加和overrides字段。

 const theme = createMuiTheme({
     palette: {
         /* you should already have stuff here, keep it */
     },
     typography: {
         /* you should already have stuff here, keep it */
     },

     overrides: {
         MuiListItem: {
             root: {
                 backgroundColor: "red",
             },
         },
     },
 });

推荐阅读