1

Possible Duplicate:
Is there a CSS parent selector?

Lets say I have this html

<div class="house"><span class="zombie"/></div>
<div class="house"><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"

Community
  • 1
  • 1
Levitikon
  • 7,569
  • 8
  • 53
  • 72

2 Answers2

1

You can't. This is the one thing that CSS can't do.

jQuery has the :has() pseudo-selector.

Pekka
  • 431,103
  • 135
  • 960
  • 1,075
0

You can't do it with CSS alone. You can however quite easily with jQuery.

$('.house:has(.vampire)').doStuff();

or

$('.house').has('.vampire').doStuff();
Madara's Ghost
  • 165,920
  • 50
  • 255
  • 304