html - first-child issue in CSS -


this question has answer here:

:)

why first paragraph not have red background?

html:

    <div class="item">          <h1><a href="http://localhost/test">test</a></h1>              <p>this new entry </p>              <p>this new entry</p>      </div>

css:

.item p:first-child {background:red}

demo: http://jsfiddle.net/tv90yrbz/

many this.

because it's not first child, h1 is.

you can use first-of-type:

.item p:first-of-type {background:red} 

http://jsfiddle.net/tv90yrbz/2/


older browsers aren't supported though:

http://caniuse.com/#search=first-of-type


Comments