How to choose the first class by class that comes after a similar element without a class?

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/

+3
source share
3 answers

try it.

.container .red:nth-child(2)
{
color: red;
}
+1
source

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/

+1
source
.container p[class=red]:nth-child(2)
        {
            color: red;
        }
0
source

All Articles