You can (ab)use the adjacent sibling combinator (+
) to achieve this with CSS that works in IE7/8.
See: http://jsfiddle.net/thirtydot/LvvNL/64/
/* equivalent to li:nth-child(1) */
#nav-primary ul li:first-child a {
border-top: 5px solid red;
}
/* equivalent to li:nth-child(2) */
#nav-primary ul li:first-child + li a {
border-top: 5px solid blue;
}
/* equivalent to li:nth-child(3) */
#nav-primary ul li:first-child + li + li a {
border-top: 5px solid green;
}
You cannot emulate more complex variations of :nth-child()
such as :nth-child(odd)
or :nth-child(4n+3)
with this method.