有效的 HTML 和 TD 元素的数量

发布于 2024-07-28 21:59:56 字数 170 浏览 2 评论 0原文

我有一个包含几列和几行的 HTML 表格。 最后一行并不总是具有与其他行一样多的 TD 元素。 它在我检查过的几个浏览器中正确呈现并通过了验证检查。 但这似乎是不正确的。 每行中 TD 元素的数量应该相同吗?

编辑:无论有或没有 colspans 和 rowspans 都可能发生这种情况。

I have a HTML table with several columns and several rows. The last row does not always have as many TD elements as the other rows. It renders correctly in several browsers I have checked and passes validation checks. But it seems incorrect. Should the number of TD elements be the same in every row?

EDIT: This could happen with or without colspans and rowspans.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤城病女 2024-08-04 21:59:57

该规范明确允许行之间的列数不一致< /a> (至少在标记中,浏览器应该生成额外的标记来弥补差异)。

列数等于具有最多列的行所需的列数,包括跨多列的单元格。 对于列数少于此数量的任何行,应使用空单元格填充该行的末尾。

…但是,坦率地说,这样的数据结构很少有任何意义。 因此,如果行长度不一致,那么您可能做错了什么。

The specification explicitly allows for inconsistent numbers of columns between rows (in markup at least, the browser is expected to generate extra ones to make up the difference).

The number of columns is equal to the number of columns required by the row with the most columns, including cells that span multiple columns. For any row that has fewer than this number of columns, the end of that row should be padded with empty cells.

… but, frankly, it's very rare that such a data structure would make any sense at all. So if you have inconsistent row lengths, then you are probably doing something wrong.

柳若烟 2024-08-04 21:59:57

“每一行的 TD 元素数量应该相同吗?”

虽然这不是严格要求的,但我说“是的,或者你应该有 colspan 来补偿它们。”

<table>
    <tr>
        <td>two</td>
        <td>columns</td>
    </tr>
    <tr>
        <td colspan="2">one big column</td>
    </tr>
</table>

尽管 W3C 规范没有要求,但我对此的看法是,当考虑到浏览器支持任何内容的方式参差不齐时,我会使用 colspans 或空单元格使其尽可能一致,以确保它在所有浏览器上都完全符合我的要求。

第二个好处是对于维护代码的任何人来说。 使意图更加明显,而不是被视为可能的错误。

"Should the number of TD elements be the same in every row?"

Though it is not strictly required, I say "yes, or you should have colspans to compensate for them."

<table>
    <tr>
        <td>two</td>
        <td>columns</td>
    </tr>
    <tr>
        <td colspan="2">one big column</td>
    </tr>
</table>

My take on this, despite that it is not required by the W3C spec, is that when considering how spotty browsers are about the way they support anything, I'd make it as consistent as possible, using colspans or empty cells, to make sure that it's doing exactly what I want on all browsers.

The secondary benefit is for anyone maintaining your code. Makes it more obvious what is intended, rather than it being percieved as a possible error.

薄情伤 2024-08-04 21:59:57

HTML 标准中不要求每行定义的列数匹配。 可以说,从道德或最佳实践的角度来看,您“应该”提供统一数量的列,我支持这一点,但标准并不要求这样做,这就是它验证的原因。

There is no requirement in HTML standards that the number of columns defined by each row match. It can be said that you "should" provide a uniform number of columns, from a moralistic or best-practices standpoint, and I'd support that, but it isn't required by standard, which is why it's validating.

萝莉病 2024-08-04 21:59:57

只是一个想法:尝试使用元素创建表格;-) 渲染表格时存在一些问题。

Just an idea: try to create your table with element ;-) There are some issues in rendering tables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文