微信小程序重定义checkbox/radio 选中样式

在做微信小程序项目时候,经常遇到需要自定义需要的多选/单选按钮的样式,现针对该问题做出如下总结:

1.样式一

 微信小程序重定义checkbox/radio 选中样式

css:

/*重写单选框样式*/

/*radio未选中时样式 */

radio .wx-radio-input{

height: 30rpx;

width: 30rpx;

margin-top: -4rpx;

border-radius: 50%;

border: 2rpx solid #999;

background: #fff!important;

}

/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */

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

border-color: #FF5757!important;

/* 居中 */

display: flex;

justify-content: center;

align-items: center;

}

/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */

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

/* 去除对号 */

content: '';

width: 20rpx;

height: 20rpx;

border-radius: 50%;

background-color: #FF5757;

}

 

2样式二

微信小程序重定义checkbox/radio 选中样式

css

.checkbox .wx-checkbox-input {
  border-radius: 32rpx; /* 圆角 */
  width: 32rpx; /* 背景的宽 */
  height: 32rpx; /* 背景的高 */
  border: 2px solid rgb(255, 85, 85);
}

.checkbox .wx-checkbox-input-disabled {
  border-radius: 32rpx; /* 圆角 */
  width: 32rpx; /* 背景的宽 */
  height: 32rpx; /* 背景的高 */
  background: #f3f3f3;
  border: 1px solid rgba(201, 201, 201, 1);
}

.checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  background: rgb(255, 85, 85);
   border: 2px solid rgb(255, 85, 85);
}

.checkbox  .wx-checkbox-input.wx-checkbox-input-checked::before {
  width: 32rpx;
  height: 32rpx;
  line-height: 32rpx;
  text-align: center;
  font-size: 24rpx;
  color: #fff;
  background: transparent;
  transform: translate(-50%, -50%) scale(1);
  -webkit-transform: translate(-50%, -50%) scale(1);
}

.checkbox .wx-checkbox-input {
  border-radius: 32rpx; /* 圆角 */
  width: 32rpx; /* 背景的宽 */
  height: 32rpx; /* 背景的高 */
  border: 1px solid rgba(201, 201, 201, 1);
}

.checkbox .wx-checkbox-input-disabled {
  border-radius: 32rpx; /* 圆角 */
  width: 32rpx; /* 背景的宽 */
  height: 32rpx; /* 背景的高 */
  background: #f3f3f3;
  border: 1px solid rgba(201, 201, 201, 1);
}

.checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  background: rgb(255, 85, 85);
}

.checkbox  .wx-checkbox-input.wx-checkbox-input-checked::before {
  width: 32rpx;
  height: 32rpx;
  line-height: 32rpx;
  text-align: center;
  font-size: 24rpx;
  color: #fff;
  background: transparent;
  transform: translate(-50%, -50%) scale(1);
  -webkit-transform: translate(-50%, -50%) scale(1);
}