English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
CSS Pseudo-class :only-of-type represents any element that does not have other elements of the same type as siblings.
Complete CSS Selector Reference Manual
Specify each p element that belongs to a specific type of unique child element of the parent element::
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> <style> div { border: 1px solid #ccc; margin: 20px; padding: 10px 10px 10px 30px; } p:only-of-type { color: red; } </style> </head> <body> <div> <p>I am the only paragraph element in this div.</p> <ul> <li>List Item</li> <li>List Item</li> </ul> </div> <div> <p>This div contains multiple paragraphs.</p> <p>I am also a paragraph.</p> <ul> <li>List Item</li> <li>List Item</li> </ul> </div> </body> </html>Test See ‹/›
element:only-of-type { style properties }
:only-of-type represents any element that does not have other elements of the same type as siblings.
The numbers in the table indicate the first browser version that supports this attribute.
Selector | |||||
---|---|---|---|---|---|
:only-of-type | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |