HTML CSS examples for CSS Selector:first-child
Select every <p> element who is the first child of its parent
<!DOCTYPE html> <html> <head> <style> p:first-child {<!-- w ww . ja v a 2s .c o m--> background-color: red; } </style> </head> <body> <p>This paragraph is the first child of its parent (body).</p> <h1>Welcome</h1> <p>This paragraph is not the first child of its parent.</p> <div> <p>This paragraph is the first child of its parent (div).</p> <p>This paragraph is not the first child of its parent.</p> </div> </body> </html>