问题
Please help me with this validation error. I can't understand what it means or what's not standards complaint with my HTML.
I'll repost it here since hopefully I'll fix it and that link will no longer work:
Table column 2 established by element td has no cells beginning in it.
…="tooltip_table"><tr><td colspan="2">20 yd range</td></tr><tr><td colspan="2"
↑
回答1:
HTML 5.2 Draft: Section 4.9.12.1 Forming a table
http://w3c.github.io/html/tabular-data.html#forming-a-table
Step 22: If there exists a row or column in the table containing only slots that do not have a cell anchored to them, then this is a table model error.
回答2:
When you say colspan="2"
, the column is supposed to stretch across two columns. My guess would be that there is no second column defined anywhere else in the able, thus making colspan="2"
impossible (and unnecessary).
I can't find anything in the spec explicitly saying it's illegal. Maybe the table calculating algorithm quoted in that spec is different from 4.01, but it's way too late in my time zone to try and get around that :)
However, I find the error message makes too perfect sense to be an outright bug.
Table column 2 established by element td has no cells beginning in it.
By using colspan="2"
, you imply the existence of a second column, which doesn't exist in that case. Common sense tells me it is correct to nag about.
Maybe somebody can shed some light on this... Or it is, indeed, a bug.
回答3:
I believe it is a bug, and still unfixed. Consider this example page and run it through the W3C validator. It gives errors for "Table column 3 established by element td has no cells beginning in it.", and yet each table has 4 cells/columns, and the "colspan" of 2 is called on the second cell.
回答4:
Looks like an issue with the HTML5 validator. That error does not come up if you validate is with HTML 4.01 Transitional, and the table html has not been changed that much in html5.
http://validator.w3.org/check?uri=http://www.wowpanda.net/s9712&charset=(detect+automatically)&doctype=HTML+4.01+Transitional&ss=1&outline=1&group=0&verbose=1&user-agent=W3C_Validator/1.654
Reporting it is probably a good idea
回答5:
I had the same error on a dynamically created table. Depending on the input, some rows were displayed or not. Like this:
Causes no error:
<table>
<tr>
<td> cell 1 in row 1 </td>
<td> cell 2 in row 1 </td>
</tr>
<tr>
<td colspan=2> one cell in row 2 </td>
</tr>
</table>
Causes no error:
<table>
<tr>
<td> cell 1 in row 1 </td>
<td> cell 2 in row 1 </td>
</tr>
</table>
Causes an error:
<table>
<tr>
<td colspan=2> one cell in what is now the only row </td>
</tr>
</table>
Once I programmed the page to delete the colspan from the last example when the first row was not displayed, the error disappeared. Something like this:
<?php if (first row with two cells is displayed) echo 'colspan=2'; ?>
I find this logical. colspan=2 with only single cells is like telling someone visiting me to turn right on a street that does not have any junctions, believing that they will continue straight on. They won't. Instead they will get hung up searching for something that is not there. Maybe not a completely accurate analogy, but you can imagine a dumb browser creating display errors while looking for stuff that you tell it is there, but is not. Browsers shouldn't be expected to "think" that maybe you meant your code differently from how you wrote it.
回答6:
Just fixing the link for Alohci's answer.
https://w3c.github.io/html/single-page.html#forming-a-table
- If there exists a row or column in the table containing only slots that do not have a cell anchored to them, then this is a table model error.
回答7:
This thread is a bit old but I post this for anyone bumping into it.
Defining each column using tag removes the message and also gives the colspan something to relate to.
More info in the answer here: Why is colspan not applied as expected
回答8:
If you initiate the table - it fixes the validation column errors. If your table has 8 columns then the first row must have 8 elements, which if you are only initiating you don't want to see. The css element is: tr.Init{border:none;} and the following first row of an 8 column table. The result is - you don't see the first row and your validation errors are fixed.
来源:https://stackoverflow.com/questions/2292947/help-with-html-validation-error-table-column-has-no-cells-beginning-in-it