So we want to access -n+3 li
elements in a list (if there are different types of elements before the li
elements we want to access is a detail we do not care about) and I used the following way:
<html>
<body>
<style>
li:nth-child(-n+3) {
background: #ff0000;
}
</style>
<p>An unordered list:</p>
<ul>
<h1>heading</h1>
<li>coffee</li>
<li>tea</li>
<li>water</li>
<li>coca-cola</li>
<li>sprite</li>
<li>orange juice</li>
<li>beer</li>
</ul>
</body>
</html>
And it works fine, however in Explorer 8 and earlier versions, nth-child()
selector is not supported. So how can we access the -n+3 li
elements without using the pseudo class nth-child()
?