CSS for elements that have certain children elements? [duplicate]
Possible Duplicate:
Is there a CSS parent selector?
Lets say I have this html
<div class="house"><span class="zombie"/></div>
<div class="house"&g开发者_StackOverflow社区t;<span class="vampire"/></div>
<div class="house"><span class="zombie"/></div>
How could I write a bit of CSS to target "div .house" that only has children with "span .vampire"? And "div .house" might not always be the direct parent of "span .zombie"
You can't. This is the one thing that CSS can't do.
jQuery has the :has()
pseudo-selector.
You can't do it with CSS alone. You can however quite easily with jQuery.
$('.house:has(.vampire)').doStuff();
or
$('.house').has('.vampire').doStuff();
精彩评论