微信小程序使用 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);
}

猜你喜欢

转载自blog.csdn.net/dark_cy/article/details/126869762