Saturday, November 24, 2018

html - How to apply css to outer div if ul item contains li items



I have two cases in my rendered HTML page.



Case 1:





  • A

  • B


Testing here



Case 2:








    In case 1, I want to apply CSS to the div if ul element contains li elements). I don't want anything for case 2. I want a pure CSS approach without any jQuery/JavaScript.


    Answer



    In addition to UncaughtTypeError's answer.



    There is a selector :not(:empty) for applying css to element if it has a child.



    Check the :not(:empty) for more details about the selector.






    * {
    box-sizing: border-box;
    }
    ul:not(:empty) + .test {
    background: black;
    color: white;
    padding: 5px;

    }


    • A

    • B


    Testing here



      Testing here





      No comments:

      Post a Comment

      plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

      In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...