为什么我不能有< table>在< h2>内? [英] Why can’t I have a <table> inside an <h2>?

查看:74
本文介绍了为什么我不能有< table>在< h2>内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解这是怎么回事:

I would like to understand what is wrong with this:

<body>
    <h2>
        <table>
        <tr>
            <td> Text</td>
        </tr>
        </table>
    </h2>
</body>

验证人抱怨: 文档类型此处不允许元素表";缺少对象","ins","del",地图",按钮"开始标签之一

Validator complains: document type does not allow element "table" here; missing one of "object", "ins", "del", "map", "button" start-tag

进一步的解释是:

所提到的元素不允许出现在放置它的上下文中;提到的其他元素是唯一允许在此使用并且可以包含提到的元素的元素.这可能意味着您需要一个包含元素,或者可能您忘记了关闭上一个元素.

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

此消息的一个可能原因是您试图将一个块级元素(例如"<p>"或"<table>")放入一个内联元素(例如"<a>","<span>"或"<font>").

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>",or "<font>").

h2和table都是块级的,因此最后的注释似乎不适用.我想要一个具有h2大小的元素的表,这是所有...告诉表使用与h2相同的大小的正确方法是什么?

Both h2 and table are block level so the last comment does not seem to apply. I want a table with h2 sized elements that is all... What is the right way to tell table to use the same size that h2 uses?

谢谢!

推荐答案

CSS.标题中根本不允许使用表,因为它没有语义.您是否看过标题为桌子的一本书章节?不要使用HTML语义标记来显示外观;自己设置样式.

CSS. Tables are simply not allowed inside headings, since it makes no semantic sense. Have you ever seen a book chapter whose title was a table? Don't use HTML semantic tags for appearance; style them yourself.

table是被CSS阻止还是内联并不重要,只有HTML DTD表示它们是什么.在此处中查找:只有流"元素是允许进入td.单击链接以查看流"的定义:您将看到它是内联"或阻止".您可以继续跟踪这些链接,直到找到该链接为止,例如sub很好,span ...也很好,但是您找不到table.

It doesn't matter whether table is block or inline by CSS, only what the HTML DTD says they are. Look here: only "flow" elements are allowed into td. Follow the link to see the definition of "flow": you'll see it's "inline" or "block". You can continue to follow those links down, until you find that, e.g. sub is fine, as is span... but you won't find table.

也-表甚至不是display: block-它们具有自己的布局值display: table.没关系.

Also - tables are not even display: block - they have their own layout value, display: table. Not that it matters.

这篇关于为什么我不能有&lt; table&gt;在&lt; h2&gt;内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆