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,749
  • 9
  • 56
  • 74

2 Answers2

1

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

jQuery has the :has() pseudo-selector.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
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
  • 172,118
  • 50
  • 264
  • 308