CSS 如何禁用样式组件内 material-ui 按钮的悬停效果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50264638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:10:53  来源:igfitidea点击:

How to disable the hover effect of material-ui button inside of a styled component

cssreactjshovermaterial-uistyled-components

提问by ccd

I added the css hover property to disable the button's hover effect, but it seems not work for my case, how should I fix this?

我添加了 css 悬停属性来禁用按钮的悬停效果,但它似乎不适用于我的情况,我应该如何解决这个问题?

import Button from 'material-ui/Button'
import styled from 'styled-components'

const StyledButton = styled(Button)`
  &:hover {
    background: none;
  }
`
export const SubmitButton = ({ onClick }) => {
  return (
    <StyledButton
      variant="raised"
      onClick={onClick}>
      login
    </StyledButton>
  )
}

回答by ccd

You can solve this problem by adding an inline style

您可以通过添加内联样式来解决此问题

export const SubmitButton = ({ onClick }) => {
  return (
    <StyledButton
      variant="raised"
      onClick={onClick}
      style={{ backgroundColor: 'transparent' }} >
      login
    </StyledButton>
  )
}

回答by Nishant Mehta

Try setting it to the same color as the background:

尝试将其设置为与背景相同的颜色:

root = {
    backgroundColor: "#FFF"
    "&:hover": {
        //you want this to be the same as the backgroundColor above
        backgroundColor: "#FFF"
    }
}