Search code examples
csscss-selectors

using nth-child in tables tr td


<table>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
</table>

Here is my code, I want <td>s with "$" with a background of #CCC in all the <tr>s.

Can any one help me how to do this using nth-child, pseudo classes?


Solution

  • table tr td:nth-child(2) {
        background: #ccc;
    }
    

    Working example: http://jsfiddle.net/gqr3J/