CSS :nth-last-of-type(an+b) pseudo class represent all sibling elements of same type whose sibling position is obtained by putting n=0,1,2,3… and so on counting from last.
CSS :nth-last-of-type values
The values are same as :nth-of-type. Only different is position counting starts from last.
Example – :nth-last-of-type
Change background of initial 2 siblings of type p counting from last
<style type="text/css" media="screen"> .box > p:nth-last-of-type(-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 :nth-last-child
- Css :first-child selector - first child element
- Css :first-of-type selector - first child element 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