css 每天一练之模拟单选按钮

效果图

html结构

<ul class="radioes">
    <li>
        <input type="radio" name="radio" id="radio1" checked>
        <label for="radio1"></label>
    </li>
    <li>
        <input type="radio" name="radio" id="radio2">
        <label for="radio2"></label>
    </li>
    <li>
        <input type="radio" name="radio" id="radio3">
        <label for="radio3"></label>
    </li>
    <li>
        <input type="radio" name="radio" id="radio4">
        <label for="radio4"></label>
    </li>
</ul>

css样式

ul,li{
    list-style: none;
    margin: 0;
    padding: 0;
}
.radioes{
    margin: 100px auto;
}
.radioes li{
    float: left;
    margin: 0 10px;
}
.radioes input{
    display: none;
}
.radioes label{
    display: block;
    width: 100px;
    height: 50px;
    background-color: #ccc;
    border-radius: 50px;
    position: relative;
    transition: all ease .5s;
}
.radioes label:after{
    content: '';
    width: 48px;
    height: 48px;
    background-color: #fff;
    border-radius: 50%;
    position: absolute;
    left: 2px;
    top: 1px;
    transition: all ease .5s;
}
.radioes input:checked + label:after{
    left: 50px;
}
.radioes input:checked + label{
    background-color: #4ace55;
}

欢迎访问我的博客,同步发布
感谢阅读,如有错误欢迎指正。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容