更新时间:2022-12-07 10:39:56
简单的答案是否,CSS无法帮助您取消选中该复选框。.
The simple answer is NO, CSS cannot help you uncheck the checkbox..
BUT
您可以使用CSS 检测是否输入通过使用
元素。 。:checked
和:not(:checked)
来检查
You can use CSS to detect whether the input
element is checked or not by using :checked
and :not(:checked)
..
测试用例: 演示
HTML
<ul>
<li>
<input type="checkbox" checked />
<label for="">Checked</label>
</li>
<li>
<input type="checkbox">
<label for="">Unchecked</label>
</li>
<li>
<input type="checkbox" checked>
<label for="">Checked Again</label>
</li>
</ul>
CSS
input:checked + label {
color: green;
}
input:not(:checked) + label {
color: red;
}