您的位置:首页 > Web前端 > CSS

自定义input[type="radio"]的样式

2018-01-18 08:51 351 查看


<html>
<body style="margin:100px">
<div class="female">
    <input type="radio" id="female" name="sex" />
    <label for="female">女</label>
</div>
<br/>
<div class="male">                
    <input type="radio" id="male" name="sex" />
    <label for="male">男</label>
</div>

<style type="text/css">
*{margin: 0px;padding: 0px;}
    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; 
      padding: .2em;
}

input[type="radio"]:checked + label::before {
    background-color: #01cd78;
    background-clip: content-box;
    padding: .2em;
}

input[type="radio"] {
    position: absolute;
    clip: rect(0, 0, 0, 0);
}
</style>
 
 
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: