CSS | :last-child Selector
The :last-child Selector is used to target the last child element of it’s parent for styling. This selector is same as “:nth-last-child”.
Syntax:
:last-child { //property }
Example:
<!DOCTYPE html> < html > < head > < style > p:last-child { background: limegreen; color: white; font-style: italic; font-size: 1.875em; } </ style > </ head > < body > < p >I am first child.</ p > < p >I am second child.</ p > < p >I am third child.</ p > < p >I am last child.</ p > </ body > </ html > |
chevron_right
filter_none
Output:
Supported Browsers:
- Google Chrome 4.0
- Edge 9.0
- Firefox 3.5
- Safari 3.2
- Opera 9.6
Recommended Posts:
- HTML | DOM lastChild Property
- CSS | ::after Selector
- CSS | #id Selector
- CSS | * Selector
- CSS | ::before selector
- CSS | :not Selector
- CSS | :lang Selector
- CSS | :nth-last-child() Selector
- CSS | ::first-letter Selector
- CSS | [attribute$=value] Selector
- CSS | :nth-child() Selector
- CSS | ::first-line Selector
- CSS | :indeterminate Selector
- CSS | Class Selector
- CSS | :focus Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.