6
<div id="main">
    <div id="sub">
    </div>
</div>

Can I set main's style from sub's style?

Jeaf Gilbert
  • 11,495
  • 19
  • 78
  • 105
  • possible duplicate of [Is there a CSS parent selector?](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – Wesley Murch Dec 19 '11 at 13:51

3 Answers3

10

Cascading Stylesheets only go (cascade) down, so they're not designed to do this at all...even in those rare cases it would be very handy if they did.

You need either JavaScript, in-line style or a different layout to get the stying you're after...but pure CSS affecting the parent isn't an option here unfortunately.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
0

Using CSS4 selectors, the original question could be solved with this:

li! > a.active { /* styles to apply to the li tag */ }
kleopatra
  • 51,061
  • 28
  • 99
  • 211
adel
  • 1
0

This would be possible with Javascript, but not with pure CSS.

fredley
  • 32,953
  • 42
  • 145
  • 236