使用背景图修改radio、checkbox样式

如果觉得使用CSS伪类设置样式太麻烦,或者页面上选中的样式太复杂CSS无法模拟,也可以用背景图去替换样式
<div class="">
<label><input type="radio" name="1"><i class="spot"></i>123456</label>
<label><input type="radio" name="1"><i class="spot"></i>123456</label>
</div>
<style>
label{
display:inline-block;
200px;
height:50px;
line-height:.8rem;
text-align:left;
position: relative;
}
label input{
15px;
height: 15px;
vertical-align: bottom;
margin-right:.1rem;
opacity: 0;
}
.spot{
display:inline-block;
17px;
height:17px;
background:url("image/radio.png") no-repeat; /*默认的样式图片*/
background-size:16px;
position: absolute;
top:.2rem;
left:0;
z-index:5;
}
input:checked + .spot{
background:url("image/checked.png") no-repeat; /*选中后的样式图片*/
background-size:16px;
}
</style>
 
原文地址:https://www.cnblogs.com/da-yao/p/8081168.html