Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we set parent element style from child style?

Tags:

css

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

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

like image 775
Jeaf Gilbert Avatar asked Sep 23 '10 10:09

Jeaf Gilbert


People also ask

How do I traverse from parent to child in CSS?

In a css selector if we need to traverse from parent to child we use > symbol. To get all the immediate children we have to specify * symbol after parent node in the css expression. So the customized css should be parent > *.

Is there a parent selector in CSS?

The element>element selector is used to select elements with a specific parent. Note: Elements that are not directly a child of the specified parent, are not selected.

How do you apply style to several specific element types?

You will begin by using the type selector to select HTML elements to style. Then, you will combine selectors to identify and apply styles more precisely. Lastly, you will group several selectors to apply the same styles to different elements.


1 Answers

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.

like image 194
Nick Craver Avatar answered Sep 20 '22 22:09

Nick Craver