Revision 319397 of :last-of-type

  • Revision slug: CSS/:last-of-type
  • Revision title: :last-of-type
  • Revision id: 319397
  • Created:
  • Creator: matt_basta
  • Is current revision? No
  • Comment The example here was terrible because it had the same effect as using :last-child, which is confusing.

Revision Content

{{ CSSRef() }}

Summary

The :last-of-type CSS pseudo-class represents the last sibling of the given type in the list of children of its parent element.

Syntax

element:last-of-type { style properties }

Example

To match the last em element inside a p element, you can use this:

p em:last-of-type {
  color: lime;
}
<p>
  <em>I'm not lime :(</em>
  <em>I'm lime :D</em>
  <strong>I'm not lime :(</strong>
  <strong>I'm also not lime :(</strong>
</p>

Specifications

Specification Status Comment
{{ SpecName('CSS4 Selectors', '#last-of-type-pseudo', ':last-of-type') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 Selectors', '#last-of-type-pseudo', ':last-of-type') }} {{ Spec2('CSS3 Selectors') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1.9.1") }} 9.0 9.5 3.2
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{ CompatGeckoMobile("1.9.1") }} 9.0 10.0 3.2

See also

  • {{ Cssxref(":nth-last-of-type") }}
  • {{ Cssxref(":first-of-type") }}
  • {{ Cssxref(":nth-of-type") }}
  • CSS3 Reference

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>:last-of-type</code> <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">CSS pseudo-class</a> represents the last sibling of the given type in the list of children of its parent element.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">
element:last-of-type { <em>style properties</em> }
</pre>
<h2 id="Example" name="Example">Example</h2>
<p>To match the last <font face="Courier New, Andale Mono, monospace"><span style="line-height: normal;">em&nbsp;</span></font>element inside a <code>p</code> element, you can use this:</p>
<pre class="brush: css">
p em:last-of-type {
&nbsp; color: lime;
}
</pre>
<pre class="brush: html">
&lt;p&gt;
&nbsp; &lt;em&gt;I'm not lime :(&lt;/em&gt;
  &lt;em&gt;I'm lime :D&lt;/em&gt;
&nbsp; &lt;strong&gt;I'm not lime :(&lt;/strong&gt;
&nbsp; &lt;strong&gt;I'm also not lime :(&lt;/strong&gt;
&lt;/p&gt;</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS4 Selectors', '#last-of-type-pseudo', ':last-of-type') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 Selectors', '#last-of-type-pseudo', ':last-of-type') }}</td>
      <td>{{ Spec2('CSS3 Selectors') }}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1.9.1") }}</td>
        <td>9.0</td>
        <td>9.5</td>
        <td>3.2</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>2.1</td>
        <td>{{ CompatGeckoMobile("1.9.1") }}</td>
        <td>9.0</td>
        <td>10.0</td>
        <td>3.2</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>{{ Cssxref(":nth-last-of-type") }}</li>
  <li>{{ Cssxref(":first-of-type") }}</li>
  <li>{{ Cssxref(":nth-of-type") }}</li>
  <li><a class="external" href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#last-of-type-pseudo">CSS3 Reference</a></li>
</ul>
Revert to this revision