返回到:CSS 伪类(Pseudo-classes) | CSS教程
:checked 选择器匹配每个选中的输入元素(仅适用于单选按钮或复选框)。
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | 谷歌 | IE | 火狐 | 苹果 | opera |
---|---|---|---|---|---|
:checked | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
为所有选中的输入元素设置背景颜色:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Web176教程(web176.com)</title> <style> input:checked { height: 50px; width: 50px; } </style> </head> <body> <form action-xhr="#"> <input type="radio" checked="checked" value="male" name="gender" /> Male<br> <input type="radio" value="female" name="gender" /> Female<br> <input type="checkbox" checked="checked" value="Bike" /> I have a bike<br> <input type="checkbox" value="Car" /> I have a car </form> </body> </html>