How do I change the background color of the element if a child element exists?

0

I have the body tag and the background color will change if there is a div.login as a child.

...
<body>
  <div class="container"><div class="login"></div></div>
<body>
...
    
asked by anonymous 10.02.2018 / 17:14

1 answer

0

There are no parent selectors in CSS.

There are several ways to dynamically select the parent of an element, but they all involve a bit of JavaScript, such as jQuery's parent () method.

Using SASS, you can do something using the ampersand operator:

Try using:

div.container {
    body & {
      background-color: red;
  }
}

I'm starting now, I do not know if it's the best way to do it. Test and see if it works. I hope I have helped !!

    
23.03.2018 / 18:28