:last-of-type

:last-of-type – pseudo-class | Selectors Level 3

The :last-of-type selects the last sibling of given type.

Syntax

element:last-of-type{
    style properties
}

Example

The HTML code

<div>
    <p>Paragraph - 1</p>
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
    <p>Paragraph - 2</p>
    <div>I am a div.</div>
</div>
p:last-of-type{
    background:#FFB7C5;
}

The paragraph-2 is selected because is the last element of its parent and it is of required type – <p>

Paragraph – 1

  • 1
  • 2

Paragraph – 2

I am a div.

Related

Resources