Jeaf Gilbert
Jeaf Gilbert

Reputation: 11981

Can we set parent element style from child style?

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

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

Upvotes: 6

Views: 7268

Answers (3)

adel
adel

Reputation: 1

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

li! > a.active { /* styles to apply to the li tag */ }

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630349

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.

Upvotes: 10

fredley
fredley

Reputation: 33871

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

Upvotes: 0

Related Questions