小编给大家分享一下纯css如何实现选框选中效果,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
选择器介绍:
1、“+”:如 div + p 选择紧接在 <div> 元素之后的所有 <p> 元素。
2、:checked :如 input:checked 单选框和复选框的选中状态。
实现代码:
<style type="text/css">
.che-box {
display:inline;
}
.che-box input{
display: none;
}
.che-box label{
display: inline-block;
border: 1px solid #e1e1e1;
border-radius: 4px;
padding: 3px 5px;
}
.che-box input:checked + label{
border-color: #088de8;
background: #088de8;
color: #fff;
}
</style>
<div class="che-box">
<input type="checkbox" id="che1" />
<label for="che1">
标签1
</label>
</div>
<div class="che-box">
<input type="checkbox" id="che2" />
<label for="che2">
标签2
</label>
</div>
实现效果:

这情况主要用于 type=“checkbox,radio”的input 自定义选中样式的。
看完了这篇文章,相信你对纯css如何实现选框选中效果有了一定的了解,想了解更多相关知识,欢迎关注天达云行业资讯频道,感谢各位的阅读!