Maison > Article > interface Web > css自定义checkbox之<label><input>纠葛_html/css_WEB-ITnose
来CSDN的处女问呢:
故事起因于我要单纯地用css自定义一个checkbox的样式,然后我是这样做的:
<input id = "my-checkbox" type = "checkbox"/><label for = "my-checkbox"></label>
input[type="checkbox"]{opacity:0;}input[type="checkbox"] + label:before{background:#d5d5d5; content:""; height: 15px; width: 15px; position: absolute; top: 0; left: 0; }
你再加个span不就行了
<style type="text/css">input[type="checkbox"]{opacity:0;}input[type="checkbox"] + span:before{background:#d5d5d5; content:" "; }input[type="checkbox"]:checked + span:before{background:#ff0000; }</style></head><body><label><input type="checkbox"/><span></span>xxxxxxxxxxxxxxxxxxx</label>
问题确实按此解决了,谢谢!