:checked CSS 偽類選擇器表示任何處于選中狀態(tài)的radio( <input type="radio">), checkbox ( <input type="checkbox">) 或("select") 元素中的option HTML元素("option")。
為所有選中的輸入元素設(shè)置背景顏色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(cainiaoplus.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 選擇器匹配每個(gè)選中的輸入元素(僅適用于單選按鈕或復(fù)選框)。
表格中的數(shù)字表示支持該屬性的第一個(gè)瀏覽器版本號(hào)。
| 選擇器 | |||||
|---|---|---|---|---|---|
| :checked | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |