背景顏色
wxml代碼
-
<button class='btn' bindtap='sumbit' >確定</button>
wxss代碼
-
.btn {
-
width: 90%;
-
margin-top: 30rpx;
-
background-color: #FFCC00;
-
color: #FFF;
-
}
background-color屬性是修改背景顏色的,color是修改字體顏色的,這里注意:如果組件里面寫 type='....',修改背景顏色會(huì)無(wú)效,例如以下代碼:
-
<!--修改背景顏色無(wú)效-->
-
<button class='btn' bindtap='sumbit' type='primary'>確定</button>
按鈕去邊框
小程序里提供的button組件默認(rèn)帶有邊框,去掉按鈕邊框只需要在wxss樣式代碼中添加:
-
.btn::after {
-
border: 0;
-
}
按鈕點(diǎn)擊時(shí)的背景顏色
wxml代碼
-
<button class='btn' bindtap='sumbit' hover-class='btn_hover'>確定</button>
-
wxss代碼
-
-
.btn_hover {
-
background-color: pink;
-
}
這里,hover-class是重點(diǎn),小程序文檔中這樣解釋這個(gè)屬性:
類型:String 默認(rèn)值:button-hover 說(shuō)明:指定按鈕按下去的樣式類。當(dāng)hover-class='none'時(shí),沒(méi)有點(diǎn)擊效果。