微信小程序—更改默认单,复选框样式

本文详细介绍了如何在小程序中自定义复选框和单选框的样式,包括未选中和选中状态的背景及对勾样式,适用于希望提升用户体验的开发者。

/*更改复选框的样式 */(小程序默认不让更改)

未选中的 背景样式

checkbox .wx-checkbox-input{

    border-radius: 8rpx;

    width: 28rpx;

    height: 28rpx;

    margin: 0 15rpx 4rpx 0;

    border-color: transparent;

    background: transparent;

}

选中后的 背景样式

checkbox .wx-checkbox-input.wx-checkbox-input-checked{

    border-color: transparent;

    background: transparent;

}

选中后的 对勾样式

checkbox .wx-checkbox-input.wx-checkbox-input-checked:before{
    
    border-radius: 8rpx;

    width: 28rpx;

    height: 28rpx;

    line-height: 28rpx;

    text-align: center;

    font-size: 30rpx;

    color: #1296db;

    background: transparent;

    transform: translate(-50%,-50%) scale(1);

    -webkit-transform: translate(-50%,-50%) scale(1);

}

/*更改单选框样式*/

radio .wx-radio-input{

    border-radius: 8rpx;

    width: 28rpx;

    height: 28rpx;

    margin: 0 15rpx 4rpx 0;

}

radio .wx-radio-input.wx-radio-input-checked{

    border-color: #cbe9fc;

    background: #1aad19;

} //这个对单选框选中后背景样式修改无效果,可在页面中radio标签中修改属性color

radio .wx-radio-input.wx-radio-input-checked:before{

    border-radius: 8rpx;    

    width: 28rpx;

    height: 28rpx;

    line-height: 28rpx;

    text-align: center;

    font-size: 28rpx;

    color: #fff;

    background: transparent;
    
    transform: translate(-50%,-50%) scale(1);

    -webkit-transform: translate(-50%,-50%) scale(1);

}

 

Tip:更改为单、复选框样式时将 checkbox /radio 批量全替换成 radio/ checkbox 即可(单选框样式和以上样式设定可能会有点出入,可根据实际情况进行调整)

 

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值