user1170330 user1170330 - 1 month ago 9
HTML Question

Table with several titles

I want to creat a table with several titles to highlight different areas.

Basically, the structure needs to look like that:

<table border="1">
<tr>
<td>Title 1</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 3</td>
<td>Col 4</td>
</tr>
<tr>
<td>Title 2</td>
</tr>
<tr>
<td>Col 5</td>
<td>Col 6</td>
</tr>
<tr>
<td>Col 7</td>
<td>Col 8</td>
</tr>
<tr>
<td>Col 8</td>
<td>Col 10</td>
</tr>
</table>


But I'm not sure, whether it's valid code.

Is there a proper tag for the title?

Here is a FIDDLE.

Answer

A proper way would be like this, using th with a colspan of 2 to span the 2 columns.

<table border="1">
  <tr>
    <th colspan="2">Title 1</th>
  </tr>
  <tr>
    <td>Col 1</td>
    <td>Col 2</td>
  </tr>
  <tr>
    <td>Col 3</td>
    <td>Col 4</td>
  </tr>
  <tr>
    <th colspan="2">Title 2</th>
  </tr>
  <tr>
    <td>Col 5</td>
    <td>Col 6</td>
  </tr>
  <tr>
    <td>Col 7</td>
    <td>Col 8</td>
  </tr>
  <tr>
    <td>Col 8</td>
    <td>Col 10</td>
  </tr>
</table>

Comments