Laxmidi
Laxmidi

Reputation: 2684

CSS Question-- Selecting Div Class Based on Its Child

Sorry for a basic question. But, I need some help.

In CSS, how can I select a div class only when it has a specific child? So, for example:

<div class="specialClass">
   <div id="myDiv"></div>
</div>

Let's say I only want to change specialClass' background to red, if it has a child called myDiv.

what_selector? {
      background-color: #FF0000;
    }

Thank you.

-Laxmidi

Upvotes: 1

Views: 1069

Answers (1)

Pedro Correia
Pedro Correia

Reputation: 813

You can't! Selectors go down the document tree.

Also without demerit to @Jeroen, don't use w3schools as a reference. It is known to provide wrong and outdated information.

Check out Sitepoint's CSS Reference for accurate and updated CSS intel.

Maybe if you further explain your goal, we can suggest a solution.

Upvotes: 2

Related Questions