修改el-button按钮背景色后,按钮失去了elementUI原有的hover和active的效果

文章讨论了ElementUI中的el-button--primary组件在hover和active状态下的样式问题,特别提到当添加not(.is-disabled)条件时,active状态的透明度只在hover时生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

应完整修改为:

<el-button type="primary" icon="el-icon-plus" @click="addUser">新增用户</el-button>

.el-button--primary:not(.is-disabled) {
    background-color: #1174de;
    border-color: #1174de;
    &:hover {
      &:not(.is-disabled) {
        opacity: 0.8;
      }
      &:active {
        opacity: 1;
      }
    }
  }

注意:.el-button--primary:后要增加not(.is-disabled),否则disabled状态下也有完整透明度的背景色

存疑:为什么&:active在&:hover内才生效?

### 如何在 Element UI 中禁用 `el-button` 按钮的悬停样式 为了移除 `el-button` 组件上的悬停效果,可以通过自定义 CSS 来覆盖默认的行为。具体来说,在 `.el-button:hover` 上应用特定的选择器并重置其样式可以达到目的。 ```css <style> /* 移除按钮悬停时的效果 */ .el-button:hover { background-color: #409eff !important; border-color: transparent !important; color: #fff !important; } </style> ``` 如果希望更彻底地消除任何视觉变化,还可以进一步调整其他可能影响外观的属性: ```css <style> /* 更全面地移除悬停状态下的样式改变 */ .el-button:hover { background-color: initial !important; border-color: initial !important; color: inherit !important; box-shadow: none !important; transform: none !important; } </style> ``` 对于 scoped 样式表中的情况,则需使用深度作用符来确保样式能够穿透到子组件内部[^1]。 ```html <template> <button class="custom-el-button">点击这里</button> </template> <style scoped> .custom-el-button /deep/ .el-button:hover, .custom-el-button >>> .el-button:hover { /* 定义去除悬停样式的规则 */ background-color: initial !important; border-color: initial !important; color: inherit !important; box-shadow: none !important; transform: none !important; } </style> ``` 需要注意的是,随着 Vue Element Plus 版本更新,某些语法可能会有所变动;例如 `/deep/`, `>>>` 可能会被新的方式取代。因此建议查阅最新文档确认最佳实践。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值