Page Widget How to - Style table column background








Question

We would like to know how to style table column background.

Answer


<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of HTML table column groups</title>
</head><!--from   w w w .  j a v  a 2s . c o m-->
<body>
  <table border="1" cellpadding="10">
    <colgroup>
      <col style="background: #bed65a;">
      <col style="background: #f8d97f;">
    </colgroup>
    <tr>
      <td>row 1, cell 1</td>
      <td>row 1, cell 2</td>
    </tr>
    <tr>
      <td>row 2, cell 1</td>
      <td>row 2, cell 2</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: