【CSS】设置按钮disabled时的样式

还原一下写此文的场景:微信小程序中,点击button,设置disabled的值为true时,button样式就变灰了:

button标签:

<button class='bottomBtn' bindtap="doWorkBtn" disabled="{{btnDisabled}}">btn</button>

button样式:

.bottomBtn {
  width: 100%;
  height: 49px;
  font-size: 18px;
  color: white;
  background: #730000;
  border-radius: 0;
}

点击事件:

 doWorkBtn: function () {
    this.setData({
      btnDisabled: true,
    })
  },

点击前和点击后效果如下:

可以清楚的看到,设置了disabled为true属性后,button背景颜色和字体颜色都变了。

那么如何修改默认样式?很简单,在css中添加下面的样式即可:

/** 必须提升样式优先权(!important) **/
button[disabled] {
  color: white !important;
  background: #730000 !important;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值