[英]How to back-trace in CSS trying to change div color when checkbox inside div is checked?
I have one div
which have one checkbox, I am trying to change color of div
when checkbox checked - unchecked using HTML
CSS
only without using JavaScript
. 我有一个带有一个复选框的
div
,我试图在选中复选框时更改div
颜色-仅使用HTML
CSS
而不使用JavaScript
取消选中。 But as CSS
doesn't support backtrace I am not sure how to achieve this. 但是由于
CSS
不支持回溯,所以我不确定如何实现。
CSS: CSS:
.content {
height: 50px;
width:50px;
border: 1px solid black;
}
HTML: HTML:
<div class="content">
<input type="checkbox">
</div>
I have wrapped the checkbox
and the span
inside a label
and then added the CSS below: 我已经将
checkbox
和span
包裹在label
,然后在下面添加了CSS:
label { height: 50px; width: 50px; border: 1px solid black; display: inline-block; position: relative; } .content { display: inline-block; position: absolute; height: 100%; width: 100%; top: 0; z-index: -1; left: 0; } input:checked+span { background-color: red }
<label for="check"> <input type="checkbox"> <span class="content"> </span> </label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.