我尝试使用图片而不是复选框。点击后,它会覆盖图像上的复选标记。这个html是来自强大专业人士的auto gen,因此我试图用css来做。
感谢您的帮助。
#frm_checkbox_83-0 {border: 1px solid red;}
#frm_checkbox_83-0 input[type="checkbox"] {display: none; }
#frm_checkbox_83-0 input[type="checkbox"] {
background: url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/christmasLights.png') 0 0px no-repeat;
z-index: 10;
content: "";
display: inline-block;
font-size: 12px;
height: 75px;
width: 75px;
line-height: 16px;
margin: -2px 6px 0 0;
text-align: center;
vertical-align: middle;
position: relative;
border-radius: 10px;
background-color: #6283B2;
}
#frm_checkbox_83-0 input[type="checkbox"]:checked {
background: url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/checkmark.png'), url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/christmasLights.png') 0 0px no-repeat;
height: 75px;
width: 75px;
border-radius: 10px;
background-color: #37924A;
}

<div class="frm_opt_container">
<div class="frm_checkbox" id="frm_checkbox_83-0">
<label for="field_a8mjgv-0">
<input type="checkbox" name="item_meta[83][]" id="field_a8mjgv-0" value="Option 1"/> Option 1
</label>
</div>
<div class="frm_checkbox" id="frm_checkbox_83-1">
<label for="field_a8mjgv-1">
<input type="checkbox" name="item_meta[83][]" id="field_a8mjgv-1" value="Option 2"/> Option 2
</label>
</div>
</div>
&#13;
答案 0 :(得分:0)
您的HTML排序似乎存在一些问题(在标签之外和之前移动复选框输入)
使用css同时锁定标签和复选框,同时隐藏复选框。
#frm_checkbox_83-0 {
border: 1px solid red;
}
#frm_checkbox_83-0 input[type="checkbox"] {
display: none;
}
#frm_checkbox_83-0 input[type="checkbox"] + label {
content: "";
background: url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/christmasLights.png') 0 0px no-repeat;
display: inline-block;
font-size: 12px;
height: 75px;
width: 75px;
margin: -2px 6px 0 0;
text-align: center;
vertical-align: middle;
border-radius: 10px;
background-color: #6283B2;
}
#frm_checkbox_83-0 input[type="checkbox"]:checked + label {
background: url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/checkmark.png'), url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/christmasLights.png') 0 0px no-repeat;
height: 75px;
width: 75px;
border-radius: 10px;
background-color: #37924A;
}
<div class="frm_opt_container">
<div class="frm_checkbox" id="frm_checkbox_83-0">
<input type="checkbox" name="item_meta[83][]" id="field_a8mjgv-0" value="Option 1" />
<label for="field_a8mjgv-0">
Option 1
</label>
</div>
<div class="frm_checkbox" id="frm_checkbox_83-1">
<label for="field_a8mjgv-1">
<input type="checkbox" name="item_meta[83][]" id="field_a8mjgv-1" value="Option 2" />Option 2
</label>
</div>
</div>