Doug Fir Doug Fir - 4 months ago 9
CSS Question

nth-child() or first-child? how to select first AND second child in one

I'd like to select the first two list items in an unordered list. I can select the first item thus:

ul li:nth-child(1) a {
background: none repeat scroll 0 0 beige;
}


OR

ul li:first-child a {
background: none repeat scroll 0 0 beige;
}


I'd like to select both the first and second line item - how do I do that?

T I T I
Answer

Without the use of js or :nth-child (which I believe is not supported in IE)

ul li:first-child, ul li:first-child + li {
    list-style: none;
}

Here is a demo tested in IE7