【发布时间】:2016-09-26 04:55:15
【问题描述】:
当我把标签放在复选框之后,这个 CSS 选择器就起作用了。
input[type=checkbox]:checked + label {
color: red;
}
<input type="checkbox"><label>Checkbox1</label>
但我想让复选框在点击标签时也被选中。
这是更新后的 HTML 的 CSS。
label > input[type=checkbox]:checked {
color: red;
}
<label><input type="checkbox">Checkbox1</label>
我在这里做错了什么?
这是一个文件中的简化 HTML 和样式。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Selectors Test Ground</title>
<style>
label > input[type=checkbox]:checked {
color: red;
}
</style>
</head>
<body>
<form id="checkBoxForm">
<ul>
<li>
<label><input type="checkbox">Checkbox1</label>
</li>
<li>
<label><input type="checkbox">Checkbox2</label>
</li>
<li>
<label><input type="checkbox">Checkbox3</label>
</li>
</ul>
</form>
</body>
【问题讨论】:
-
:active 伪类怎么样?
标签: html css css-selectors