微信小程序使用 checkbox 如何修改样式?

  主要通过 .wx-checkbox-input.wx-checkbox-input-checked 以及 .wx-checkbox-input-checked::before 三个类名来设置 checkbox 的样式。

.wx-checkbox-input 用于设置未选中时框的样式

checkbox .wx-checkbox-input {
	width: 32rpx; 
    height: 32rpx;
    border-color: #409eff;
    background-color: transparent;
    transition: background-color .2s;
}

在这里插入图片描述

.wx-checkbox-input-checked 用于设置选中后框的样式,为了覆盖原生样式,需要与 .wx-checkbox-input 类连写,否则权重不够。

checkbox .wx-checkbox-input.wx-checkbox-input-checked {
	color: #fff; /* 这里也可以设置对钩的颜色 */
    background-color: #409eff;
}

在这里插入图片描述

.wx-checkbox-input-checked::before 用于设置选中后对钩的样式,也需要与 .wx-checkbox-input 类连写。

checkbox .wx-checkbox-input {
	/* content: ""; */ /* 不想显示对钩可以将 content 置空 */
	width: 32rpx;
    height: 32rpx;
    line-height: 32rpx;
    color: #fff;
    font-size: 32rpx;
    text-align: center;
    background-color: transparent;
    transform: translate(-50%, -50%) scale(1);
}
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值