mozilla

Revision 26886 of :nth-of-type

  • Revision slug: CSS/:nth-of-type
  • Revision title: :nth-of-type
  • Revision id: 26886
  • Created:
  • Creator: jswisher
  • Is current revision? No
  • Comment Removed gecko-specific header; 14 words removed

Revision Content

Summary

The :nth-of-type pseudo-class matches an element that has an+b-1 siblings with the same element name before 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. This is a more flexible and useful pseudo selector if you want to ensure you're selecting the same type of tag no matter where it is inside the parent element, or what other different tags appear before it.

Syntax

element:nth-of-type(an + b) { style properties }

Examples

This example causes the positions of floated images to alternate between right and left.

img:nth-of-type(2n+1) { float: right; }
img:nth-of-type(2n) { float: left; }

Browser compatibility

{{ CompatibilityTable() }}

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

See also

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <code>:nth-of-type</code> <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 with the same element name before 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. This is a more flexible and useful pseudo selector if you want to ensure you're selecting the same type of tag no matter where it is inside the parent element, or what other different tags appear before it.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">element:nth-of-type(<em>a</em>n + <em>b</em>) { <em>style properties</em> }
</pre>
<h3 id="Examples" name="Examples">Examples</h3>
<p>This example causes the positions of floated images to alternate between right and left.</p>
<pre class="brush: css">img:nth-of-type(2n+1) { float: right; }
img:nth-of-type(2n) { float: left; }
</pre>
<h3 id="Browser_compatibility">Browser compatibility</h3>
<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.1</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>9.5</td> <td>3.1</td> </tr> </tbody> </table>
</div>
<h3 id="See_also" name="See_also">See also</h3>
<ul> <li>{{ Cssxref(":nth-child") }}</li> <li><a class="external" href="http://www.w3.org/TR/css3-selectors/#nth-of-type-pseudo">CSS3 Reference</a></li>
</ul>
Revert to this revision