使用CSS修改radio样式

前言

文中使用两种方式修改默认的radio和checkbox图标。
1.伪元素方法
2.字体图标方法

Radio

效果图
方法一:使用伪元素
<input class="radio_type" type="radio" name="type" id="radio1" checked="checked"/> 
<label for="radio1">radio1</label>
<input class="radio_type" type="radio" name="type" id="radio2" /> 
<label for="radio2">radio2</label>
label{
    line-height: 20px;
    display: inline-block;
    margin-left: 5px;
    margin-right:15px;
    color: #777;
}
.radio_type{
    width: 20px;
    height: 20px;
    appearance: none;
    position: relative;
}
.radio_type:before{
    content: '';
    width: 20px;
    height: 20px;
    border: 1px solid #7d7d7d;
    display: inline-block;
    border-radius: 50%;
    vertical-align: middle;
}
.radio_type:checked:before{
    content: '';
    width: 20px;
    height: 20px;
    border: 1px solid #c59c5a;
    background:#c59c5a;
    display: inline-block;
    border-radius: 50%;
    vertical-align: middle;
}
.radio_type:checked:after{
    content: '';
    width: 10px;
    height:5px;
    border: 2px solid white;
    border-top: transparent;
    border-right: transparent;
    text-align: center;
    display: block;
    position: absolute;
    top: 6px;
    left:5px;
    vertical-align: middle;
    transform: rotate(-45deg);
}
.radio_type:checked+label{
    color: #c59c5a;
}

圆形款只需稍微修改一下css便好


image.png
label{
   line-height: 20px;
   display: inline-block;
   margin-left: 5px;
   margin-right:15px;
   color: #777;
}
.radio_type{
   width: 20px;
   height:20px;
   appearance: none;
   position: relative;
}
.radio_type:before{
   content: '';
   width: 20px;
   height: 20px;
   border: 2px solid #EDD19D;
   display: inline-block;
   border-radius: 50%;
   vertical-align: middle;
}
.radio_type:checked:before{
   content: '';
   width: 20px;
   height: 20px;
   border: 2px solid #EDD19D;
   display: inline-block;
   border-radius: 50%;
   vertical-align: middle;
}
.radio_type:checked:after{
   content: '';
   width: 12px;
   height: 12px;
   text-align: center;
   background:#EDD19D;
   border-radius: 50%;
   display: block;
   position: absolute;
   top: 6px;
   left: 6px;
}
.radio_type:checked+label{
   color: #EDD19D;
}

方法二:使用字体图标

用到再记录吧。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,104评论 1 92
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 28,780评论 1 45
  • 学会使用CSS选择器熟记CSS样式和外观属性熟练掌握CSS各种选择器熟练掌握CSS各种选择器熟练掌握CSS三种显示...
    七彩小鹿阅读 6,443评论 2 66
  • HTML 5 HTML5概述 因特网上的信息是以网页的形式展示给用户的,因此网页是网络信息传递的载体。网页文件是用...
    阿啊阿吖丁阅读 4,914评论 0 0
  • 新成员加入---白龙马:师傅,我们出发吧!
    F56春雨sunny阅读 309评论 0 1

友情链接更多精彩内容