HTML CSS examples for CSS Selector:only-of-type
The :only-of-type selector selects element that is the only child of its type within its parent.
Select <p> element that is the only child of its type, of its parent:
<!DOCTYPE html> <html> <head> <style> p:only-of-type {<!-- w ww .jav a 2 s . c om--> background: red; } </style> </head> <body> <div><p>This is a paragraph.</p></div> <div><p>This is a paragraph.</p><p>This is a paragraph.</p></div> </body> </html>