纯css美化radio选择框的样式

效果图如下:

简洁的HTML:

   <label>
        <input type="radio" name="1" id="" class="a-radio">
        <span class="b-radio"></span>好
    </label>

    <label>
        <input type="radio" name="1" id="" class="a-radio">
        <span class="b-radio"></span>很好
    </label>

    <label>
        <input type="radio" name="1" id="" class="a-radio">
        <span class="b-radio"></span>很棒
    </label>

CSS部分:
1.利用 点击label = 点击input控件
2.使用到了CSS相邻兄弟元素选择器~

<style>
        body{
            font-size: 18px;
            line-height: 20px;
        }
        label{
            margin:10px;
        }
        .a-radio{
            display: none;
        }
        .b-radio{
            display: inline-block;
            border:1px solid #ccc;
            width:16px;
            height: 16px;
            border-radius:2px;
            vertical-align: middle;
            margin-right: 5px;
            position: relative;
        }
        .b-radio:before{
            content: '';
            font-size: 0;
            width: 10px;
            height: 10px;
            background: rgb(143, 188, 238);
            position: absolute;
            left:50%;
            top:50%;
            margin-left: -5px;
            margin-top: -5px;
            border-radius: 2px;
            display: none;
        }
        .a-radio:checked~.b-radio:before{
            display: block;
        }
    </style>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • HTML 5 HTML5概述 因特网上的信息是以网页的形式展示给用户的,因此网页是网络信息传递的载体。网页文件是用...
    阿啊阿吖丁阅读 9,670评论 0 0
  • •前端面试题汇总 一、HTML和CSS 21 你做的页面在哪些流览器测试过?这些浏览器的内核分别是什么? ...
    Simon_s阅读 6,572评论 0 8
  • CSS 是什么 css(Cascading Style Sheets),层叠样式表,选择器{属性:值;属性:值}h...
    崔敏嫣阅读 5,345评论 0 5
  • 前端开发面试题 面试题目: 根据你的等级和职位的变化,入门级到专家级,广度和深度都会有所增加。 题目类型: 理论知...
    怡宝丶阅读 7,378评论 0 7
  • 今天晚上开月会仔细聆听佳人的分享,向好的佳人学习
    ATurbo阅读 663评论 0 0