:nth-last-child

  • Revision slug: Web/CSS/:nth-last-child
  • Revision title: :nth-last-child
  • Revision id: 494305
  • Created:
  • Creator: kscarfone
  • Is current revision? No
  • Comment Updated tags

Revision Content

{{ CSSRef() }}

Summary

The :nth-last-child CSS pseudo-class matches an element that has an+b-1 siblings after it in the document tree, for a given positive or zero value for n, and has a parent element. See {{ Cssxref(":nth-child") }} for a more thorough description of the syntax of its argument.

Syntax

element:nth-last-child(an + b) { style properties }

Examples

Example selectors

tr:nth-last-child(-n+4)
Matches the last four rows of an HTML table.
span:nth-last-child(even)
Matches the even elements in their parent element, starting at the last element and working backward.

Specifications

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

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.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-child") }}

 

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>:nth-last-child</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> matches an element that has <code><em>a</em>n+<em>b</em>-1</code> siblings after it in the document tree, for a given positive or zero value for <code>n</code>, and has a parent element. See {{ Cssxref(":nth-child") }} for a more thorough description of the syntax of its argument.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">
element:nth-last-child(<em>a</em>n + <em>b</em>) { <em>style properties</em> }
</pre>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example_selectors" name="Example_selectors">Example selectors</h3>
<dl>
 <dt>
  <code>tr:nth-last-child(-n+4)</code></dt>
 <dd>
  Matches the last four rows of an HTML table.</dd>
 <dt>
  <code>span:nth-last-child(even)</code></dt>
 <dd>
  Matches the even elements in their parent element, starting at the last element and working backward.</dd>
</dl>
<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', '#nth-last-child-pseudo', ':nth-last-child') }}</td>
   <td>{{ Spec2('CSS4 Selectors') }}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS3 Selectors', '#nth-last-child-pseudo', ':nth-last-child') }}</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>4.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-child") }}</li>
</ul>
<p>&nbsp;</p>
Revert to this revision