HTML CSS examples for CSS Selector:last-child
The :last-child selector selects the last element inside its parent.
:last-child is equal to :nth-last-child(1).
Select the <p> element that is the last child of its parent:
<!DOCTYPE html> <html> <head> <style> p:last-child {<!-- w ww . ja v a 2 s . c om--> background: #ff0000; } </style> </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>