1

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 ?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

It works, and you're right, I wanted it to span 3 but it counted the row it was on. Your code works as well for the table as for the W3C Validator, but is this the legit, proper way to do it ? However, thank you very much !
I'm not sure what you mean by "legit" and "proper"? The rowspan attribute indicates that the cell spans that many rows, one of which is the row it's in. It works and passes validation - is there another perspective or standard you're concerned about?
Maintainer of the W3C HTML Checker here. This answer is the right answer and you should accept it (check-mark it). It’s not just a right answer, it is the right answer—that is, it’s the “legit, proper way” to achieve that effect that the HTML markup in the question seems to be trying for.
As far as validation goes, table border=1 is also going to cause the HTML checker to emit an error message. So you need to instead use CSS to get the border styling; for example, if you want something that looks like what border=1 gives you, you can use some CSS like this: table { border-style: outset; border-width: 1px; border-spacing: 2px; } td, th { border-style: inset; border-width: 1px; }
I used CSS in my full code, I just put the border=1 here to only share the table. Thank you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.