通过”:checked“配合其他标签来自定义复选框样式
Html代码:
<form action="#"> <div class="wrapper"> <div class="box"> <input type="checkbox" checked="checked" id="username" /> <span>√</span> </div> <label for="username">我是选中状态</label> </div> <div class="wrapper"> <div class="box"> <input type="checkbox" id="userpwd" /> <span>√</span> </div> <label for="userpwd">我是未选中状态</label> </div> </form>Css代码:
form{ border:1px solid #ccc; padding: 20px; width: 300px; margin: 30px auto;} .wrapper{ margin-bottom: 10px;} .box{ display: inline-block; width:20px; height: 20px; position: relative; border: 2px solid orange; margin-right: 5px; vertical-align:middle; } .box input{ opacity: 0; position: absolute; top:0; left: 0;} .box span{ position: absolute; top: -10px; right: 3px; font-size: 30px; font-weight: bold; font-family: Arial; -webkit-transform: rotate(30deg); transform: rotate(30deg); color: orange; } input[type="checkbox"] + span{ opacity: 0;} input[type="checkbox"]:checked + span{ opacity:1;}
原文地址:http://blog.csdn.net/comeonstone/article/details/45150237