Christian Giangreco Christian Giangreco - 1 month ago 10
HTML Question

HTML Table column count issue

I'm doing an HTML table for a school work, but I don't get it through the W3C Validator. At first I got some "Stray end tag tr" errors, but after fixing it, it keeps showing me the warning :


A table row was 1 columns wide, which is less than the column count established by the first row (3).


I actually understand what it means, but I can't seem to find how to fix it. I tried some stuff but it always messed up the table.

After fixing the "Stray end tag tr" errors, I got this code:

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


The final table looks like this:



Do you have any idea ?

Answer

I think that the rowspan cells cause that row to count as a single cell. I think you would need to combine them with the following row using something like:

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

If it helps, what indicated the problem to me was that the rowspan values were 1 higher than they should be - you didn't actually want the cell to span 4 rows, you wanted it to span 3 but the row it was on counts as one of them.

Comments