如何禁用样式组件内 material-ui 按钮的悬停效果
How to disable the hover effect of material-ui button inside of a styled component
我添加了 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>
)
}
你可以通过添加内联样式来解决这个问题
export const SubmitButton = ({ onClick }) => {
return (
<StyledButton
variant="raised"
onClick={onClick}
style={{ backgroundColor: 'transparent' }} >
login
</StyledButton>
)
}
尝试将其设置为与背景相同的颜色:
root = {
backgroundColor: "#FFF"
"&:hover": {
//you want this to be the same as the backgroundColor above
backgroundColor: "#FFF"
}
}
如果您改为使用带有 className 的原始 Button 组件,则可以像这样向按钮添加 disableRipple。
<Button disableRipple>
您可以尝试将按钮的背景设置为none
button: {
'&:hover': {
background: 'none',
},
}
如果有人需要,这是 v5 的解决方案
<IconButton
disableElevation
disableRipple
size="small"
sx={{
ml: 1,
"&.MuiButtonBase-root:hover": {
bgcolor: "transparent"
}
}}
>
</IconButton>
您可以通过样式化组件覆盖它:
const StyledButton = styled(Button)`
&:hover {
background-color: transparent;
}
`;
我添加了 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>
)
}
你可以通过添加内联样式来解决这个问题
export const SubmitButton = ({ onClick }) => {
return (
<StyledButton
variant="raised"
onClick={onClick}
style={{ backgroundColor: 'transparent' }} >
login
</StyledButton>
)
}
尝试将其设置为与背景相同的颜色:
root = {
backgroundColor: "#FFF"
"&:hover": {
//you want this to be the same as the backgroundColor above
backgroundColor: "#FFF"
}
}
如果您改为使用带有 className 的原始 Button 组件,则可以像这样向按钮添加 disableRipple。
<Button disableRipple>
您可以尝试将按钮的背景设置为none
button: {
'&:hover': {
background: 'none',
},
}
如果有人需要,这是 v5 的解决方案
<IconButton
disableElevation
disableRipple
size="small"
sx={{
ml: 1,
"&.MuiButtonBase-root:hover": {
bgcolor: "transparent"
}
}}
>
</IconButton>
您可以通过样式化组件覆盖它:
const StyledButton = styled(Button)`
&:hover {
background-color: transparent;
}
`;