HTML CSS examples for CSS Selector:first-child
The :first-child selector selects elements if it is the first child of its parent.
Select and style the first <li> element in lists:
<!DOCTYPE html> <html> <head> <style> li:first-child {<!-- w w w . j a v a 2 s . c o m--> background: red; } </style> </head> <body> <ul> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> <ol> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> </body> </html>