语法:
E:only-of-type : {attribute}
相关伪类: E:root | E:nth-child(n) | E:nth-last-child(n) | E:nth-of-type(n) | E:nth-last-of-type(n) | E:last-child | E:first-of-type | E:only-child | E:empty
说明:
匹配属于同类型中唯一兄弟元素的E
兼容性:
类型 | Internet Explorer | Firefox | Chrome | Opera | Safari |
---|---|---|---|---|---|
版本 | (×)IE6 | (×)Firefox 2.0 | (√)Chrome 1.0.x | (√)Opera 9.63 | (√)Safari 3.1 |
(×)IE7 | (×)Firefox 3.0 | (√)Chrome 2.0.x | (√)Safari 4Public beta | ||
(×)IE8 | (√)Firefox 3.5 | ||||
示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <style type="text/css"> p:only-of-type {color:#FF0000;} </style> <title>结构性伪类 E:only-of-type</title> </head> <body> <div style="width:733px; border: 1px solid #666; padding:5px;"> <div> <p>匹配属于同类型中唯一兄弟元素的E</p> </div> <div> <p>匹配属于同类型中唯一兄弟元素的E</p> <p>匹配属于同类型中唯一兄弟元素的E</p> </div> </div> </body> </html>