From W3C Wiki
< CSS‎ | Selectors

Pseudo-class :nth-last-child()

The :nth-last-child() pseudo-class represents an element that has an+b siblings after it in the document tree, for any positive integer or zero value of n, and has a parent element.


selector:nth-last-child(an+b){ properties }

Point, Note

  • The examples of an+b are as follows:
    • :nth-last-child(odd) /* represents all odd foo elements in their parent element, counting from the last one */
    • :nth-last-child(-n+2) /* represents the two last elements */



   background-color: yellow;


    <tr><td>This is first row.</td></tr>
    <tr><td>This is second row.</td></tr>
    <tr><td>This is third row.</td></tr>
    <tr><td>This is fourth row.</td></tr>

CSS defines the :nth-last-child() pseudo-class selector in :nth-last-child() pseudo-class.