First-child vs Adjacent Selector

Here is a typical way one might use :first-child: first you apply the image to all links in the list, then you remove it from the first one.

1
2
3
4
#nav li a
{background:url(images/nav-sub-div.png) 0 0 repeat-x;}
#nav li:first-child a
{background-image:transparent;}

However, using theĀ Adjacent Siblings Selector, you can streamline it:

1
2
#nav li + li a
{background:url(images/nav-sub-div.png) 0 0 repeat-x;}

The + selector applies the style to any LI that immediately follows an LI, which obviously rules out the first item. A simple solution, often overlooked.

Compatibility

IE Firefox Safari Opera Chrome
Version 7.0 8.0 9.0 2.0 3.5 3.1 4.0 9.2 9.5 2.0
+ Buggy Full Full Full Full Buggy Buggy Buggy Full Full
:first-child Buggy Buggy Full Buggy Full Buggy Full Buggy Full Full