HTML CSS examples for CSS Selector:first-of-type
The :first-of-type selector selects element that is the first child of a particular type from its parent.
It is the same as :nth-of-type(1).
Select the first <p> element of its parent:
<!DOCTYPE html> <html> <head> <style> p:first-of-type { background: red; } </style><!-- w w w .jav a 2 s . c o m--> </head> <body> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p>The fourth paragraph.</p> <div> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p>The fourth paragraph.</p> </div> </body> </html>