Role of CSS :only-of-type Selector

CSSWeb DevelopmentFront End Technology

Use the CSS :only-of-type selector to style every <p> element that is the only <p> element of its parent.

Example

You can try to run the following code to implement the :only-of-type selector

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:only-of-type {
            background: orange;
            color: white;
         }
      </style>
   </head>
   <body>
      <div>
         <p>This is demo text 1.</p>
      </div>
      <div>
         <p>This is demo text 2.</p>
         <p>This is demo text 3.</p>
         <p>This is demo text 4.</p>
      </div>
   </body>
</html>
raja
Published on 09-May-2018 10:57:54
Advertisements