You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ReactJS中如何修改/自定义MUI按钮点击时的样式?

MUI Button点击样式修改与涟漪效果控制

一、修复点击时的背景色样式

你当前代码把:active嵌套在了&:hover内部,这会导致点击样式仅在hover状态下生效,正确写法是将&:active与&:hover放在同级:

<Box component="center">
  <Button 
    sx={{
      // 默认状态样式
      backgroundColor: 'transparent',
      color: 'black',
      '&:hover': {
        color: 'red',
        backgroundColor: 'transparent',
      },
      '&:active': {
        backgroundColor: 'transparent',
        color: 'red' // 可选:点击时保持文字红色
      },
    }}
  >
    <Typography
      sx={{
        mt: 0.5,
        textDecorationLine: "underline",
        textTransform: 'none'
      }}
    >
      Already have an account? Log in!
    </Typography>
  </Button>
</Box>

二、控制涟漪效果

MUI Button 自带disableRipple属性,直接配置即可启用或禁用涟漪:

  • 禁用涟漪:添加disableRipple={true}
  • 启用涟漪:移除该属性(默认启用)或设置disableRipple={false}

示例代码(禁用涟漪):

<Box component="center">
  <Button 
    disableRipple={true}
    sx={{
      backgroundColor: 'transparent',
      color: 'black',
      '&:hover': {
        color: 'red',
        backgroundColor: 'transparent',
      },
      '&:active': {
        backgroundColor: 'transparent',
        color: 'red'
      },
    }}
  >
    <Typography
      sx={{
        mt: 0.5,
        textDecorationLine: "underline",
        textTransform: 'none'
      }}
    >
      Already have an account? Log in!
    </Typography>
  </Button>
</Box>

内容的提问来源于stack exchange,提问作者NGIP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 07:45:51