:checked CSS 伪类选择器表示任何处于选中状态的radio( <input type="radio">), checkbox ( <input type="checkbox">) 或("select") 元素中的option HTML元素("option")。
为所有选中的输入元素设置背景颜色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(cainiaojc.com)</title>
<style>
input:checked {
height: 55px;
width: 55px;
}
</style>
</head>
<body>
<form action="">
<input type="radio" checked="checked" value="male" name="gender" />男<br>
<input type="radio" value="female" name="gender" /> 女<br>
<input type="checkbox" checked="checked" value="Bike" /> 自行车<br>
<input type="checkbox" value="Car" /> 轿车
</form>
</body>
</html>测试看看 ‹/›:checked 选择器匹配每个选中的输入元素(仅适用于单选按钮或复选框)。
表格中的数字表示支持该属性的第一个浏览器版本号。
| 选择器 | |||||
|---|---|---|---|---|---|
| :checked | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |