微信小程序中自定义单选框/多选框样式

微信小程序中自定义单选框/多选框样式

1.先看多选框

页面效果

具体代码如下

(1).wxml代码

// .wxhtml代码(只是一部分)
<checkbox-group class='checkboxList' bindchange="checkboxChange">
	<label class="checkbox" wx:for="{{filterList}}" wx:key="{{id}}">
		<checkbox value="{{item.sclass_id}}" checked="{{item.checked}}" />{{item.sclass_name}}
	</label>
</checkbox-group>

(2).wxss代码

// .wxcss代码(只是自定义多选框的代码,其余忽略)
// 重写多选框样式
  label.checkbox {
      padding-left: 20rpx;
  }
  checkbox .wx-checkbox-input{
      width: 22rpx;
      height: 22rpx;
  }
  
 // 选中后多选框样式
  checkbox .wx-checkbox-input.wx-checkbox-input-checked{
      border: 1rpx solid transparent;
      background-color: #da2728;
  }

  // 选中后对勾样式
  checkbox .wx-checkbox-input.wx-checkbox-input-checked::before{
      width: 22rpx;
      height: 22rpx;
      line-height: 22rpx;
      text-align: center;
      font-size:22rpx;
      color:#fff;
      background: transparent;
      transform: translate(-50%, -50%) scale(1);
      -webkit-transform: translate(-50%, -50%) scale(1);
  }

 

2.单选框

具体样式如下:

单选框样式

(1).wxml代码

<!-- 单选框 -->
<view>
    <radio-group class="radio-group" bindchange="radioChange">
        <label wx:for="{{items}}" wx:key="{{index}}">
            <radio value="{{item.name}}" />{{item.value}}
        </label>
    </radio-group>
</view>

(2).wxss代码

/* 单选框 */
.radio-group {
    margin-top: 20px;
    background-color: #eee;
}
.radio-group label {
    display: block;
    height: 86rpx;
    line-height: 86rpx;
    font-size: 32rpx;
    border-bottom: 1rpx solid #e2e2e2;
    box-sizing: border-box;
    padding: 0 20rpx;
}

radio {
    width: 38rpx;
}

/* 单选框未选中 */
radio .wx-radio-input {
    width: 24rpx;
    height: 24rpx;
    border-radius: 50%;
}


/* 单选框选中后对勾样式 */
radio .wx-radio-input.wx-radio-input-checked::before{
    border-radius: 50%;
    width: 44rpx;
    height: 44rpx;
    line-height: 44rpx;
    text-align: center;
    font-size: 26rpx;   
    color:#fff;
    background-color: #da2728;
    border-color: #da2728;
}

(3).wxjs代码

    // 单选按钮事件
    radioChange(e){
        console.log('单选:', e.detail.value)
    },

 

PS:如有错误之处,请批评指出,理解万岁!!!
  • 1
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值