移动端自定义单选样式

效果截图:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
          <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title></title>
        <style>
            input[type="radio"] + label::before {
                content: "\a0"; /*不换行空格*/
                display: inline-block;
                vertical-align: middle;
                font-size: 18px;
                width: 1em;
                height: 1em;
                margin-right: .4em;
                border-radius: 50%;
                border: 1px solid #01cd78;
                text-indent: .15em;
                line-height: 1; 
            }
            input[type="radio"]:checked + label::before {
                background-color: #01cd78;
                background-clip: content-box;
                padding: .1em;
                width:.9rem;
                height:.9rem;
            }
            input[type="radio"] {
                position: absolute;
                clip: rect(0, 0, 0, 0);
            }
        </style>
    </head>
    <body>
        <span class="female">
            <input type="radio" id="female" checked name="sex" />
            <label for="female"></label>
        </span>
        <span class="male">                
            <input type="radio" id="male" name="sex" />
            <label for="male"></label>
        </span>
    </body>
</html>

 

posted @ 2019-01-02 10:44  奕佚  阅读(426)  评论(0编辑  收藏  举报