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

MUI 5.0.2 ButtonGroup内Button的href属性导致右边框样式异常问询

问题结论

你描述的属于MUI 5.0.2版本的已知样式Bug,问题根因如下:

  • ButtonGroup的默认边框样式使用了:not(:last-of-type)选择器匹配组内非末尾按钮,仅给非末尾按钮隐藏默认右边框,hover状态才显示。
  • 带href属性的Button会被渲染为<a>标签,不带href属性的Button会被渲染为<button>标签,二者属于不同的DOM元素类型,导致:last-of-type选择器匹配逻辑失效,才会出现边框显示异常。

修复方案

  1. 升级MUI到5.1.0及以上版本,该版本已经修复了ButtonGroup的选择器逻辑,改用:not(:last-child)匹配规则,兼容不同标签类型的Button组件
  2. 如果暂时无法升级版本,可以添加自定义样式临时兼容:
/* 覆盖ButtonGroup默认边框规则 */
.MuiButtonGroup-root > .MuiButton-root:not(:last-child) {
  border-right-width: 0;
}
.MuiButtonGroup-root > .MuiButton-root:hover:not(:last-child) {
  border-right-width: 1px;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 13:42:00