首页 > 解决方案 > Material UI - 全球主题的多个 css 类

问题描述

我第一次使用带有 React 的 Material UI。我想改变我的全局主题,但我想改变的有两个类:

.MuiListItem-root.Mui-selected, .MuiListItem-root.Mui-selected:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

我如何选择它们createMuiTheme?我试过这个:

createMuiTheme({
  overrides: {
    MuiListItem: {
      root: {
        Mui: {
          selected: {
            backgroundColor: "black",
            "&:hover": {
              backgroundColor: "blue",
            },
          },
        },
      },
    },
  }
})

先感谢您

标签: cssreactjsmaterial-ui

解决方案


试试这段代码

createMuiTheme({
    overrides: {
        MuiListItem: {
            root: {
                '&$selected': {
                    backgroundColor: "black"
                },
                '&$selected:hover'{
                    backgroundColor: "blue"
                }
            },
        },
    },
})

看看这个回应


推荐阅读