How can I select the first element with a class of "red" (first) in this construct?
HTML:
<div class='container'> <p>Zero</p> <p class="red">First</p> <p class="red">Second</p> </div>
http://jsfiddle.net/ek9Ch/
try it.
.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*/ }
script: http://jsfiddle.net/Varinder/ek9Ch/2/
.container p[class=red]:nth-child(2) { color: red; }