Role of CSS :last-of-type Selector


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

Example

You can try to run the following code to implement the :last-child selector −

Live Demo

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

Updated on: 30-Jun-2020

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements