开发者

CSS for elements that have certain children elements? [duplicate]

This question already has answers here: Closed 11 years ago.

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜