Style every <p> elements that is the last child of its parent with CSS

CSSWeb DevelopmentFront End Technology

To style every <p> elements that is the last child of its parent, use the CSS :last-child selector. You can try to run the following code to implement the :last-child selector

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:last-child {
            background: orange;
         }
      </style>
   </head>
   <body>
      <p>This is demo text1.</p>
      <p>This is demo text2.</p>
      <p>This is demo text3.</p>
   </body>
</html>

Output

raja
Published on 08-May-2018 09:07:07
Advertisements