简体   繁体   English

Material-Ui 主题定制:hover 上包含的按钮

[英]Material-Ui theme customization: hover on contained button

So I'm trying to configure a theme for Material-Ui on my React app.所以我试图在我的 React 应用程序上为 Material-Ui 配置一个主题。 In the app I use two different type of buttons, contained and outlined.在应用程序中,我使用了两种不同类型的按钮,包含和概述。 The problem is the hover effect on the contained button (the outlined works fine) and will default to a grey hover effect.问题是包含按钮上的 hover 效果(轮廓工作正常),默认为灰色 hover 效果。

overrides: {
 MuiButton: {
  contained: {
   backgroundColor: palette.primary.main,
   color: palette.primary.contrastText,
   "&:hover": {
     backgroundColor: palette.primary.active,
   },
  },
  outlined: {
    color: palette.primary.main,
    "&:hover": {
      backgroundColor: palette.primary.active,
    },
  },
 }
}

outlined = working概述 = 工作
contained = not working包含=不工作

This is from the element inspector, where my color is the one with a strike through这是来自元素检查器,我的颜色是带有删除线的颜色
background-color:背景颜色:
#e0e0e0.MuiButton-contained:hover #e0e0e0.MuiButton-contained:hover
rgba(23, 0, 255, 0.3).MuiButton-contained:hover rgba(23, 0, 255, 0.3).MuiButton-contained:hover

Anyone got any idea what's wrong?有人知道出了什么问题吗?

You can try adding root , so something like:您可以尝试添加root ,例如:

overrides: {
 MuiButton: {
  root: {
   "&:hover": {
     backgroundColor: palette.primary.active,
   },
  }
 }
}

By default, the hover color (the background, for contained; the border, for outlined) will be palette.primary.dark .默认情况下,hover 颜色(背景,用于包含;边框,用于轮廓)将为palette.primary.dark It could be these conflicting setup might cause some issues, try setting it there.可能是这些冲突的设置可能会导致一些问题,请尝试将其设置在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM