The :last-of-type selects the element that is the last child, of a particular type, of its parent.

For e.g., in the code below the css selects the last paragraph and the last heading h2.


<!DOCTYPE html>
<html>
<head>
<style> 
p:last-of-type {
 background: #C5CAE9;
}

h2:last-of-type {
 background: #CDDC39;
}
</style>
</head>

<body>

<div class="container">
 <p>1st paragraph</p>
 <p>2bd paragraph</p>
 <p>last paragraph</p>
 <h1>1st Heading</h1>
 <h2>1st heading</h2>
 <h2>last heading</h2>
</div>

</body>
</html>

 

0 Comments

Leave a reply

Your email address will not be published. required fields are marked *