:first-child and :last-child
show page contents
How to select an element that is the first or last child of its parent.
The :first-child pseudo class means "if this element is the first child of its parent". :last-child means "if this element is the last child of its parent". Note that only element nodes (HTML tags) count, these pseudo-classes ignore text nodes.
Testsheet
div#test p:first-child {text-decoration: underline;}
div#test p:last-child {color: red;}
show page contents
How to select an element that is the first or last child of its parent.
The :first-child pseudo class means "if this element is the first child of its parent". :last-child means "if this element is the last child of its parent". Note that only element nodes (HTML tags) count, these pseudo-classes ignore text nodes.
Testsheet
div#test p:first-child {text-decoration: underline;}
div#test p:last-child {color: red;}