By using last-of-type
selector we can match the every last child of its parent element.
<style> p:last-of-type { color: blue; background-color: orange; font-family: 20px; } </style> <body> <strong>This is Strong Statement</strong> <p>This is first paragraph.</p> <p>This is last paragraph.</p> <b>This is Bold.</b> <div> <p>This is the first pargarph in div.</p> <p>This is the last paragraph in div.</p> </div> </body>
In the above code snippet we have given style to the <p>
element, so that the style applies to the last child of every <p>
element in all the parent elements.
OUTPUT