CSS :nth-last-child(an+b) pseudo class represent all sibling elements whose sibling position is obtained by putting n=0,1,2,3… and so on from last. Note that sibling can be of any type but should have same parent container element.
CSS :nth-last-child values
The values are same as :nth-child. Only different is position counting starts from last.
Example of :nth-last-child
Change background of initial 2 siblings counting from last
<style type="text/css" media="screen"> .box > :nth-last-child(-n+2) { background-color:lightgreen; } </style> <div class="box"> <p>p1</p> <p>p2</p> <p>p3</p> <p>p4</p> <p>p5</p> <div>div1</div> </div>
Related
- Css :nth-child
- CSS :nth-of-type
- Css :nth-child vs :nth-of-type
- Css :first-child selector - first child element
- Css :first-of-type selector - first child element of type
- CSS :nth-last-of-type
- Css :last-child selector - last child element
- Css :last-of-type selector - last child element of type
- CSS :only-child - define style if element if only child
- CSS :only-of-type - define style of only child a type