HTML Element Style How to - Style the third column








Question

We would like to know how to style the third column.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
td:nth-child(3) {<!--  w  ww .  j  av  a  2 s.  c om-->
  background: red;
  width: 1px;
  white-space: nowrap;
}
</style>
</head>
<body>
  <table style="width: 100%" border="1">
    <tr>
      <td>Static length</td>
      <td>Static length</td>
      <td><div>Length varies varies varies</div></td>
      <td>Space filler</td>
    </tr>
    <tr>
      <td>Static length</td>
      <td>Static length</td>
      <td><div>Length varies</div></td>
      <td>Space filler</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: