2

Possible Duplicate:
Is there a CSS parent selector?

Given I have no way to change the HTML file, only CSS file.

How can I add some CSS to the parent DIV if I only know the direct child DIV ID?

For example:

<div>
  <div id="child">
    content
  </div>
</div>

Anything like: #child:parent div CSS rules?

Community
  • 1
  • 1
Hao
  • 6,291
  • 9
  • 39
  • 88

2 Answers2

1

No, css selectors does not support it. In css4 there is something for it (but it is not available now):

$div > #child {
  /* here code for parent div */
}
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
0

Try this but it using jquery

$('#child').parent().css({'background-color':'green','color':'black'});

DEMO

Krish
  • 2,590
  • 8
  • 42
  • 62