帮助解决 HTML 验证错误:表格列中没有单元格开头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2292947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Help with HTML validation error: Table column has no cells beginning in it
提问by Thomas Bonini
Please help me with thisvalidation error. I can't understand what it means or what's not standards complaint with my HTML.
请帮助我解决此验证错误。我不明白这意味着什么,或者我的 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.
由元素 td 建立的表第 2 列没有以其中开头的单元格。
…="tooltip_table"><tr><td colspan="2">20 yd range</td></tr><tr><td colspan="2"
↑
采纳答案by Alohci
HTML 5.2 Draft: Section 4.9.12.1 Forming a table
HTML 5.2 草案:第 4.9.12.1 节形成表格
http://w3c.github.io/html/tabular-data.html#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.
步骤 22:如果表中存在一行或一列只包含没有锚定单元格的槽,那么这是表模型错误。
回答by Pekka
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).
当您说 时colspan="2"
,该列应该横跨两列。我的猜测是,在能力的其他任何地方都没有定义第二列,从而使colspan="2"
不可能(和不必要)。
I can't find anything in the specexplicitly 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 :)
我在规范中找不到任何明确说明这是非法的内容。也许该规范中引用的表计算算法与 4.01 不同,但在我的时区尝试解决这个问题为时已晚:)
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.
由元素 td 建立的表第 2 列没有以其中开头的单元格。
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.
通过使用colspan="2"
,您暗示存在第二列,在这种情况下不存在。常识告诉我唠叨是正确的。
Maybe somebody can shed some light on this... Or it is, indeed, a bug.
也许有人可以对此有所了解......或者它确实是一个错误。
回答by Will
I believe it is a bug, and still unfixed. Consider this example pageand 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.
我相信这是一个错误,并且仍未修复。考虑这个示例页面并通过 W3C 验证器运行它。它给出了“由元素 td 建立的表第 3 列没有单元格开头的错误。”,但每个表都有 4 个单元格/列,并且在第二个单元格上调用了 2 的“colspan”。
回答by riddler
Just fixing the link for Alohci's answer.
只需修复 Alohci 答案的链接。
https://w3c.github.io/html/single-page.html#forming-a-table
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.
- 如果表中存在仅包含没有锚定单元格的槽的行或列,则这是表模型错误。
回答by riddler
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:
一旦我对页面进行编程以在第一行未显示时从最后一个示例中删除 colspan,错误就消失了。像这样的东西:
<?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.
我觉得这是合乎逻辑的。colspan=2 只有一个单元格就像告诉访问我的人在没有任何交叉路口的街道上右转,相信他们会继续直行。他们不会。相反,他们会因为寻找不存在的东西而陷入困境。也许不是一个完全准确的类比,但你可以想象一个愚蠢的浏览器在寻找你告诉它存在但不存在的东西时会产生显示错误。不应期望浏览器“认为”您的代码可能与您编写代码的方式不同。
回答by glebm
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.
看起来像 HTML5 验证器的问题。如果您使用 HTML 4.01 Transitional 进行验证,则不会出现该错误,并且表格 html 在 html5 中没有发生太大变化。
Reporting it is probably a good idea
报告它可能是个好主意
回答by Nicsoft
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.
使用 tag 定义每一列会删除消息并为 colspan 提供一些相关的东西。
More info in the answer here: Why is colspan not applied as expected
此处答案中的更多信息:为什么没有按预期应用 colspan
回答by user3261298
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.
如果您启动表 - 它修复了验证列错误。如果您的表格有 8 列,那么第一行必须有 8 个元素,如果您只是开始,则不想看到这些元素。css 元素是:tr.Init{border:none;} 和下面一个 8 列表的第一行。结果是 - 您看不到第一行并且您的验证错误已修复。