html - how to pick second element starting from the last one? -
i have 2 elements , have same class , want pick second element starting last one. ( hope image tells everything)
i tried nth-child
2 elements have same class why can't nth-child
idea ?
you can use nth-last-child(2)
or nth-last-of-type(2)
, select 2nd last item.
li { display: inline-block } li:nth-last-child(2) { color: red }
<ul> <li>test</li> <li>test</li> <li>test</li> <li>test</li> <li>test</li> </ul> <hr /> <ul> <li>test</li> <li>test</li> <li>test</li> <li>test</li> <li>test</li> <li>test</li> <li>test</li> </ul>
Comments
Post a Comment