Here is the code:
CSS:
div.colored {
width: 300px;
height: 100px;
margin-bottom: 20px;
border: 1px solid black;
}
div.colored:first-child {
background-color: red;
}
div.colored:last-child {
background-color: blue;
}
div.nocolor {
width: 300px;
height: 100px;
margin-bottom: 20px;
border: 1px solid black;
}
HTML:
<p>Test 1:</p>
<div>
<div class="colored"></div>
<div class="colored"></div>
</div>
<p>Test 2:</p>
<div>
<div class="nocolor"></div>
<div class="colored"></div>
<div class="colored"></div>
<div class="nocolor"></div>
</div>
The first test does what I'd expect. The first div.colored is red and the second (last) is blue. In the second test, there are four divs. The first and last div.colored are not colored. Have I coded my css incorrectly?