This will select the last two iems of a list:
li:nth-last-child(-n+2) {color:red;}
<ul>
<li>fred</li>
<li>fred</li>
<li>fred</li>
<li>fred</li>
<li>fred</li>
<li>fred</li>
<li>fred</li>
<li>fred</li>
</ul>
More Related Contents:
- Is there a CSS parent selector?
- Complex CSS selector for parent of active child [duplicate]
- Select every Nth element in CSS
- CSS3 selector :first-of-type with class name?
- CSS Selector that applies to elements with two classes
- Why isn’t it possible to combine vendor-specific pseudo-elements/classes into one rule set?
- CSS ‘>’ selector; what is it? [duplicate]
- Select element based on multiple classes
- CSS selector based on element text? [duplicate]
- Pure CSS checkbox image replacement
- Handling a colon in an element ID in a CSS selector [duplicate]
- CSS selector for attribute names based on a wildcard
- IE8 :nth-child and :before
- CSS selector to select first element of a given class
- How to select the first, second, or third element with a given class name?
- Can I use variables for selectors?
- Combine :after with :hover
- CSS: styled a checkbox to look like a button, is there a hover?
- Are CSS3 ::before and ::after pseudo elements supported by IE9 or not?
- CSS Selector for
- How can I apply styles to multiple classes at once?
- Multiple descendant children selector with css [duplicate]
- Select odd even child excluding the hidden child
- Is there an opposite CSS pseudo-class to :hover?
- Comma in CSS, multiple selectors using the same CSS
- How to skip first child?
- How to select all elements whose ID starts and ends with specific strings?
- selector for nth nested elements
- How does CSS specificity decide which styles to apply?
- Latest on CSS parent selector [duplicate]