user3106579
user3106579

Reputation: 663

select first element css base on class name

.class + p:first-child{

}

the above code not working, unless it's element instead of class, like p:first-child.

<div class="wrap">
<h3></h3>
<div style="clear:both"></div>
<p></p>
<p></p>
<p></p>
<p></p>

how do I select first p base on the class wrap? I do not want to apply class name on p.

Upvotes: 1

Views: 178

Answers (1)

Usman
Usman

Reputation: 3278

You can't use :first-child here, because in this case first-child of class:wrap is <h3> .In your desired case try this

.wrap > p:nth-of-type(1) {
    color:red

}

Fiddle is HERE

Upvotes: 1

Related Questions