簡體   English   中英

如何禁用樣式組件內部 material-ui 按鈕的 hover 效果

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

我添加了 css hover 屬性來禁用按鈕的 hover 效果,但它似乎不適用於我的情況,我應該如何解決這個問題?

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>
  )
}

嘗試將其設置為與背景相同的顏色:

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

您可以通過添加內聯樣式來解決此問題

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

如果有人需要,這是 v5 的解決方案

         <IconButton
            disableElevation
            disableRipple
            size="small"
            sx={{
              ml: 1,
              "&.MuiButtonBase-root:hover": {
                bgcolor: "transparent"
              }
            }}
          >

          </IconButton>

您可以嘗試將按鈕的背景設置為none

button: {    
    '&:hover': {
        background: 'none',
    },
}

如果您使用帶有 className 的原始 Button 組件,您可以像這樣將 disableRipple 添加到按鈕。 <Button disableRipple>

您可以通過樣式化組件覆蓋它:

const StyledButton = styled(Button)`
    &:hover {
      background-color: transparent;
    }
`;

這應該工作

const StyledButton = styled(Button)`
  &&.MuiButton-root {
    &:hover {
      background: none;
    }
  }
`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM