Selector for all but first of class
If you want to select all other li.img and give them a different backgroundColor:
li.img ~ li.img {
background-color: blue;
}
You cannot do this with :not(:first-child)
because all li.img
elements except the first li
(no matter if it's .img
or not) are indeed not the first child of their parent. So that selector would exclude the first li.img
only if it were the first li
without qualification.
However, you can do it with the general sibling combinator ~
:
li.img ~ li.img {
background-color: blue;
}
This selector matches any li.img
that is the sibling of any other li.img
but appears after it in document order, or in other words every li.img
but the first.
See it in action, and be aware that IE < 9 does not support this selector.