Skip to content Skip to sidebar Skip to footer

Targeting First 2 Children Or Last 2 Children

I know a bunch of the pseudo classes (first-child, last-child, nth-child) but I am having trouble selecting the first 2 children in a list or the last 2, the list is dynamic and ch

Solution 1:

For the first two children you can use:

ulli:nth-child(-n + 2) {
    color: orange;
}

http://jsfiddle.net/nYnSz/1/

For the last two:

ulli:nth-last-child(-n + 2) {
    color: orange;
}

http://jsfiddle.net/nYnSz/

Post a Comment for "Targeting First 2 Children Or Last 2 Children"