Reputation: 152677
See example http://jsfiddle.net/qqyYU/1/
<div class="detail">
<p><b>Entry</b><br>
First <span>40,-</span><br>
Second <span>20,-</span></p></div>
css
.detail p span:first-child {background:yellow;}
Upvotes: 0
Views: 352
Reputation: 9774
The first-child of your <p>
is a <b>
tag, not a <span>
:
"This pseudo-class matches an element only if it’s the first child element of its parent element." (http://reference.sitepoint.com/css/pseudoclass-firstchild)
EDIT You may be able to use the adjacent sibling selector if you can't change the class of the element and you are required to support IE7 (though it may not work):
Upvotes: 3
Reputation: 17434
What you want for your CSS is:
.detail p span:nth-of-type(1) {background:yellow;}
Unfortunately this has poor browser support.
Upvotes: 2