Here is an example of my HTML and CSS. I can’t, for the life of me, figure out why the second rule is applying to all the buttons, and not just the first three.
HTML
<div id="test">
<ul>
<li><button>1</button></li>
<li><button>2</button></li>
<li><button>3</button></li>
<li><button>4</button></li>
<li><button>5</button></li>
<li><button>6</button></li>
</ul>
</div>
CSS
#test button
{
background-color: blue;
}
#test button:nth-child(-n + 3)
{
background-color: red;
}
#test button:hover {
background-color: green;
}
You’re applying
nth-childto the wrong element: there is only 1 child of eachbutton. You mean to target thelielements:http://jsfiddle.net/fCFEn/3/