Style every <p> element that has no children with CSS

CSSWeb DevelopmentFront End Technology

To style every <p> element that has no children with CSS, use the: empty selector t. You can try to run the following code to implement the: empty selector

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         p.demo {
            width: 300px;
            height: 20px;
            background: gray;
         }
         p:empty {
            width: 150px;
            height: 20px;
            background: orange;
         }
      </style>
   </head>
   <body>
      <p class = "demo">This is demo text. Below is empty text.</p>
      <p></p>
   </body>
</html>
raja
Published on 08-May-2018 13:25:09
Advertisements