热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

微信小程序如何修改radio和checkbox的默认样式和图标

这篇文章主要介绍了微信小程序修改radio和checkbox的默认样式和图标,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

wxml:


      
       第1题:企业的价值观是 ?
      
      单选
     
     

      
       

      

     

我们看一下原生的效果:

修改wxml中的redio 组件的color属性:

{{item.value}}

wxss(只有修改样式的部分):

/* 单选、多选 勾选 */


/*radio未选中时样式 */ 
radio .wx-radio-input{ 
 /* 自定义样式.... */
/* 我这里没有进行,未选中的样式修改
  height: 40rpx; 
  width: 40rpx;
  margin-top: -4rpx;
  border-radius: 50%;
  border: 2rpx solid #999;
  background: transparent;
   */

 }


/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked {
  /* border: none; */
  border-color: #2792ff!important;
  /* background-color: #fff!important; */
  /* background-color: transparent!important; */
  /* 居中 */
/* 
  display: flex;
  justify-content: center;
  align-items: center;
  */
  
}

/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked::before {
 /* 去除对号 */
 content: ''; 
 /* background: #fff; */
 width: 36rpx;
 height: 36rpx;
 border-radius: 50%;
 /* background: red; */
 background-color: #2792ff;
 /* 居中 */
 /* margin-top: 0rpx; */
 /* display: flex; */
 /* position: relative; */
 
}

修改后的单选框样式:

复选框同理

wxml:


      
       第1题:企业的价值观是 ?
      
      多选
     
     



      
       
      
     

wxss:

/*checkbox未选中时样式 */ 
checkbox .wx-checkbox-input{ 
 /* 自定义样式.... */
 border-radius: 50%;

 }


/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  /* border: none; */
  border-radius: 50%;
  border-color: #2792ff!important;

  
}

/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
 /* 去除对号 */
 content: ''; 
 /* background: #fff; */
 width: 36rpx;
 height: 36rpx;
 border-radius: 50%;
 /* background: red; */
 background-color: #2792ff;
 /* 居中 */
 /* margin-top: 0rpx; */
 /* display: flex; */
 /* position: relative; */
 
}

修改前后对比:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
author-avatar
mobiledu2502929507
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有