How can I select the first element with class "red" (First) in this construction?
HTML:
<div class='container'>
<p>Zero</p>
<p class="red">First</p>
<p class="red">Second</p>
</div>
How can I select the first element with class "red" (First) in this construction?
HTML:
<div class='container'>
<p>Zero</p>
<p class="red">First</p>
<p class="red">Second</p>
</div>
try this..
.container .red:nth-child(2)
{
color: red;
}
Ok, not very pretty but does the job:
.container p + p.red {
color: red;
}
.container p + p.red ~ p {
color:black; /*reverting back*/
}