首页  >  文章  >  web前端  >  css如何自定义radio单选框样式 ?(代码实现)

css如何自定义radio单选框样式 ?(代码实现)

不言
不言原创
2018-08-21 14:57:424971浏览

本篇文章给大家带来的内容是关于css如何自定义radio单选框样式 ?(代码实现),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

html部分

<div class="radio">
    <label>
        <input name="feel" type="radio" value="love" />
        <span class="pos">
            <span class="radio_bg">
                <span class="radio_on"></span>
            </span>
        </span>
        <span>LOVE</span>
    </label>
    <label>
        <input name="feel" type="radio" value="hate" />
        <span class="pos">
            <span class="radio_bg">
                <span class="radio_on"></span>
            </span>
        </span>
        <span>YOU ARE NICE</span>
    </label>
</div>

css样式部分

            .radio {
                width: 260px;
                height: 26px;
                line-height: 26px;
                margin: 200px auto;
                background-color: #ddeef1;
                font-size: 16px;
                color: #495060;
                text-align: center;
            }        
            label:first-child {
                margin-right: 40px;
            }
            label input, .radio_on {
              display: none;
            }            
            .pos {
                display: inline;
                vertical-align: middle;
            }        
            .radio_bg {
              position: relative;
              display: inline-block;
              height: 14px;
              width: 14px;
              border: 1px solid #B3B4B8;
              border-radius: 50%;
            }        
            label:hover .radio_bg, label input:checked + span.pos span.radio_bg {
              border: 1px solid #27B28B;
            }        
            label input:checked + span.pos span.radio_bg .radio_on {
              display: inline-block;
              position: absolute;
              top: 2px;
              left: 2px;
              width: 10px;
              height: 10px;
              border-radius: 50%;
              background-color: #27B28B;
            }

效果图

1198763118-5b7ba5eadb9ec_articlex.png

相关推荐:

HTML的checkbox和radio怎样美化样式

使用CSS自定义radio、checkbox样式的示例详解

以上是css如何自定义radio单选框样式 ?(代码实现)的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn