自定义checkbox的样式

来源:互联网 发布:大脚插件for mac 编辑:程序博客网 时间:2024/05/22 11:30

状况描述:HTML自带的checkbox,样式不一定符合需求,但没有简单的CSS属性能将其修改。
解决方案

<!--HTML--><input type="checkbox" id="checker" /><label class="checkerLabel" for="checker">Checker</label>/*CSS*/input[type="checkbox"]{display:none;}input[type="checkbox"]+label{display:inline-block;width:30px;height:30px;}input[type="checkbox"]+label::before{content:"";display:inline-block;width:16px;height:16px;border:1px solid #eee;}input[type="checkbox"]:checked+label::before{background-color:#eee;}

若要绑定事件,要绑在input上,否则会触发两次事件。

原创粉丝点击