Use colspan to span columns to several columns

Description

To span cell to multiple columns, you use the colspan attribute.

The values assigned to the colspan must be integers.

You also have to remove the cell elements that the expanded cell will cover.

Example


<!DOCTYPE HTML>
<html>
<head>
</head><!--  w  w  w .  j  av a  2 s  .  c om-->
<body>
  <table border='1'>
    <thead>
      <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Color</th>
        <th colspan="2">Size & Votes</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th>2nd Favorite:</th>
        <td>HTML</td>
        <td>HTML</td>
        <td>Oracle</td>
        <td>MySQL</td>
      </tr>
      <tr>
        <th>3rd Favorite:</th>
        <td>XML</td>
        <td colspan="2" rowspan="2">This is a test.</td>
        <td>203</td>
      </tr>
      <tr>
        <td>A</td>
        <td>B</td>
        <td>C</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <th colspan="5">&copy; 2011 java2s.com Enterprises</th>
      </tr>
    </tfoot>
  </table>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed