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,329
  • 8
  • 51
  • 71

2 Answers2

1

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

jQuery has the :has() pseudo-selector.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
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
  • 158,961
  • 49
  • 244
  • 292