CSS3 > Selectors

Last-of-type selector in CSS3

How to match the every last child of its parent element in CSS3?


By using last-of-typeselector 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


 Views: 3158 | Post Order: 28



Write for us






Hosting Recommendations