this question has answer here:
- :first-child not working expected 5 answers
:)
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:
Comments
Post a Comment