CSS 3 Module <== Test # ==>
W3C Selectors 32 of 153 of the static tests category
Testing Date Revision
:nth-child() pseudo-class (ID #28) 2004-03-03 1.0
  1. First list item
  2. This second list item should have a green background
  3. Third list item
  4. This fourth list item should have a green background
  5. Fifth list item
  6. This sixth list item should have a green background
Green row : 1.1 1.2 1.3
Green row : 2.1 2.2 2.3
Green row : 3.1 3.2 3.3
Green row : 4.1 4.2 4.3
5.1 5.2 5.3
6.1 6.2 6.3
green cell 1.2 1.3 green cell 1.5 1.6 green cell 1.8
green cell 2.2 2.3 green cell 2.5 2.6 green cell 2.8
green cell 3.2 3.3 green cell 3.5 3.6 green cell 3.8
.red { background-color : red }
ul > li:nth-child(odd) { background-color : lime }
ol > li:nth-child(even) { background-color : lime }
table.t1 tr:nth-child(-n+4) { background-color : lime }
table.t2 td:nth-child(3n+1) { background-color : lime }
<ul>
  <li class="red">This first list item should have a green background</li>
  <li>Second list item</li>
  <li class="red">This third list item should have a green background</li>
  <li>Fourth list item</li>
  <li class="red">This fifth list item should have a green background</li>
  <li>Sixth list item</li>
</ul>
<ol>
  <li>First list item</li>
  <li class="red">This second list item should have a green background</li>
  <li>Third list item</li>
  <li class="red">This fourth list item should have a green background</li>
  <li>Fifth list item</li>
  <li class="red">This sixth list item should have a green background</li>
</ol>
<div>
<table border="1" class="t1">
  <tr class="red">
<td>Green row : 1.1</td>
<td>1.2</td>
     <td>1.3</td>
</tr>
  <tr class="red">
<td>Green row : 2.1</td>
<td>2.2</td>
     <td>2.3</td>
</tr>
  <tr class="red">
<td>Green row : 3.1</td>
<td>3.2</td>
     <td>3.3</td>
</tr>
  <tr class="red">
<td>Green row : 4.1</td>
<td>4.2</td>
      <td>4.3</td>
</tr>
  <tr>
<td>5.1</td>
<td>5.2</td>
<td>5.3</td>
</tr>
  <tr>
<td>6.1</td>
<td>6.2</td>
<td>6.3</td>
</tr>
</table>

<table class="t2" border="1">
  <tr>
<td class="red">green cell</td>
<td>1.2</td>
<td>1.3</td>
      <td class="red">green cell</td>
<td>1.5</td>
<td>1.6</td>
      <td class="red">green cell</td>
<td>1.8</td>
</tr>
  <tr>
<td class="red">green cell</td>
<td>2.2</td>
<td>2.3</td>
      <td class="red">green cell</td>
<td>2.5</td>
<td>2.6</td>
      <td class="red">green cell</td>
<td>2.8</td>
</tr>
  <tr>
<td class="red">green cell</td>
<td>3.2</td>
<td>3.3</td>
      <td class="red">green cell</td>
<td>3.5</td>
<td>3.6</td>
      <td class="red">green cell</td>
<td>3.8</td>
</tr>
</table>
</div>