纯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>

猜你喜欢

转载自blog.csdn.net/connie_0217/article/details/80264183