简体   繁体   English

复选框,其中图像和覆盖图像处于选中状态

[英]Checkbox with image and overlayed image on checked state

I need help for checkbox using CSS only. 我只需要使用CSS复选框的帮助。

First of all it function correctly. 首先,它可以正常运行。 However, I want to overlay the checked image on top of the unchecked image when the button is clicked. 但是,单击按钮时,我想将选中的图像覆盖在未选中的图像之上。 How to achieve this? 如何实现呢?

 .frm_checkbox {border: 1px solid red;} .frm_checkbox input[type="checkbox"] {display: none; } input#field_32gyuu-0 { 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; } #frm_checkbox_112-0 input[type="checkbox"]:checked + label:before { background: url('http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/lightbox-checkmark.png') 0 0px no-repeat; height: 75px; width: 75px; } 
 <div id="frm_field_162_container" class="frm_form_field form-field form-group frm_top_container"> <label class="frm_primary_label control-label">Checkboxes <span class="frm_required"></span> </label> <div class="frm_opt_container"> <div class="frm_checkbox checkbox" id="frm_checkbox_162-0"> <label for="field_32gyuu-0"> <input type="checkbox" name="item_meta[162][]" id="field_32gyuu-0" value="Option 1" /> Option 1</label> </div> <div class="frm_checkbox checkbox" id="frm_checkbox_162-1"> <label for="field_32gyuu-1"> <input type="checkbox" name="item_meta[162][]" id="field_32gyuu-1" value="Option 2" /> Option 2</label> </div> </div> </div> 

I needed to wrap the label text in a span , but take a look at the code below. 我需要将标签文本包裹在span ,但请看下面的代码。 I wasn't sure if you still wanted to see the checkbox, so toggle display: none as required. 我不确定您是否仍然希望看到该复选框,因此请切换display: none要求。

 .checkbox label { position: relative; display: table; margin-bottom: 15px; padding-left: 80px; height: 75px; background-color: #eee; } .checkbox label > span { display: table-cell; vertical-align: middle; } .checkbox label > span:before { content: url("http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/christmasLights.png"); position: absolute; top: 0; left: 0; width: 75px; height: 75px; } [type="checkbox"] { display: none; margin-top: 31px; } [type="checkbox"]:checked + span:before { content: url("http://www.uswebcompany.com/plugins/formidable/wp-content/uploads/2016/01/lightbox-checkmark.png"); } 
 <div id="frm_field_162_container" class="frm_form_field form-field form-group frm_top_container"> <label class="frm_primary_label control-label">Checkboxes <span class="frm_required"></span> </label> <div class="frm_opt_container"> <div class="frm_checkbox checkbox" id="frm_checkbox_162-0"> <label for="field_32gyuu-0"> <input type="checkbox" name="item_meta[162][]" id="field_32gyuu-0" value="Option 1" /> <span>Option 1</span> </label> </div> <div class="frm_checkbox checkbox" id="frm_checkbox_162-1"> <label for="field_32gyuu-1"> <input type="checkbox" name="item_meta[162][]" id="field_32gyuu-1" value="Option 2" /> <span>Option 2</span> </label> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM