另一个标签可以在HTML 5标题内(即h1,h2,h3等......)吗?

时间:2022-11-24 23:42:13

I'm not sure about the convention regarding headings in HTML 5 but I wanted to know if I could add a <small> in a <h3>, like this (this could apply to any tag inside any heading tags):

我不确定有关HTML 5中标题的约定,但我想知道是否可以在

中添加,就像这样(这可以应用于任何标题标记内的任何标记):

<h3>Payment details <small>(this is your default card)</small></h3>

Many Thanks

4 个解决方案

#1


12  

Yes, that markup validates. You can check it yourself on http://validator.w3.org/

是的,该标记验证。您可以在http://validator.w3.org/上自行查看。

Something to be aware of with HTML5 though is a change to the notion of block-level elements: https://developer.mozilla.org/en/HTML/Block-level_elements

使用HTML5需要注意的是对块级元素概念的更改:https://developer.mozilla.org/en/HTML/Block-level_elements

#2


6  

I don't think there's any restriction on this in the spec. Only Void elements cannot have children. See http://dev.w3.org/html5/markup/syntax.html#void-element

我不认为规范中对此有任何限制。只有Void元素不能有孩子。请参阅http://dev.w3.org/html5/markup/syntax.html#void-element

Although generally the H1, H2, H3, etc. would be rendered in a single size and for a sub header like your "(this is your default card)" you might use a lower H e.g. H4.

虽然H1,H2,H3等通常会以单一尺寸呈现,而对于像“(这是您的默认卡片)”这样的子标题,您可能会使用较低的H,例如H4。

#3


5  

The specs for heading elements:

标题元素的规格:

says that it has phasing content model:

说它有分阶段内容模型:

Content model:
    Phrasing content.

Looking at the part of the specs for phasing content model:

查看分阶段内容模型的部分规范:

It says this:

它说:

Note: Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.

注意:大多数归类为短语内容的元素只能包含自身归类为短语内容的元素,而不包含任何流内容。

Aside from this, you cannot put heading in another heading - this is from W3C validator:

除此之外,您不能将标题放在另一个标题中 - 这是来自W3C验证器:

Error Line 1, Column 23: Heading cannot be a child of another heading.

<!DOCTYPE html><h1><h2></h2></h1>

Although I could not find in the specs where it explicitly says this, there are restrictions that seem rather specific. This can yield to some very odd behavior such as that the above HTML would actually be parsed as

虽然我在规范中找不到它明确说明的内容,但是有些限制看似相当具体。这可能会产生一些非常奇怪的行为,例如上面的HTML实际上会被解析为

<h1></h1><h2></h2>

e.g. see this SOq for an example of indirect issues it can cause:

例如请参阅此SOQ,了解它可能导致的间接问题的示例:

Just in case someone runs into this...

万一有人遇到这个......

#4


0  

I don't think there's any restriction on this in the spec. Only void elements cannot have children. See http://dev.w3.org/html5/markup/syntax.html#void-element

我不认为规范中对此有任何限制。只有void元素才能生成子元素。请参阅http://dev.w3.org/html5/markup/syntax.html#void-element

A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes.

void元素是一个元素,其内容模型永远不允许它在任何情况下都有内容。 Void元素可以具有属性。

The following is a complete list of the void elements in HTML:

以下是HTML中void元素的完整列表:

area, base, br, col, command, embed, hr, img, input, keygen, link,
meta, param, source, track, wbr

Although generally the h1, h2, h3, etc. would be rendered in a single size. For a sub header like your "(this is your default card)" you might use a smaller header e.g. h4.

虽然通常h1,h2,h3等将以单一尺寸呈现。对于像“(这是您的默认卡片)”这样的子标题,您可以使用较小的标题,例如H4。

#1


12  

Yes, that markup validates. You can check it yourself on http://validator.w3.org/

是的,该标记验证。您可以在http://validator.w3.org/上自行查看。

Something to be aware of with HTML5 though is a change to the notion of block-level elements: https://developer.mozilla.org/en/HTML/Block-level_elements

使用HTML5需要注意的是对块级元素概念的更改:https://developer.mozilla.org/en/HTML/Block-level_elements

#2


6  

I don't think there's any restriction on this in the spec. Only Void elements cannot have children. See http://dev.w3.org/html5/markup/syntax.html#void-element

我不认为规范中对此有任何限制。只有Void元素不能有孩子。请参阅http://dev.w3.org/html5/markup/syntax.html#void-element

Although generally the H1, H2, H3, etc. would be rendered in a single size and for a sub header like your "(this is your default card)" you might use a lower H e.g. H4.

虽然H1,H2,H3等通常会以单一尺寸呈现,而对于像“(这是您的默认卡片)”这样的子标题,您可能会使用较低的H,例如H4。

#3


5  

The specs for heading elements:

标题元素的规格:

says that it has phasing content model:

说它有分阶段内容模型:

Content model:
    Phrasing content.

Looking at the part of the specs for phasing content model:

查看分阶段内容模型的部分规范:

It says this:

它说:

Note: Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.

注意:大多数归类为短语内容的元素只能包含自身归类为短语内容的元素,而不包含任何流内容。

Aside from this, you cannot put heading in another heading - this is from W3C validator:

除此之外,您不能将标题放在另一个标题中 - 这是来自W3C验证器:

Error Line 1, Column 23: Heading cannot be a child of another heading.

<!DOCTYPE html><h1><h2></h2></h1>

Although I could not find in the specs where it explicitly says this, there are restrictions that seem rather specific. This can yield to some very odd behavior such as that the above HTML would actually be parsed as

虽然我在规范中找不到它明确说明的内容,但是有些限制看似相当具体。这可能会产生一些非常奇怪的行为,例如上面的HTML实际上会被解析为

<h1></h1><h2></h2>

e.g. see this SOq for an example of indirect issues it can cause:

例如请参阅此SOQ,了解它可能导致的间接问题的示例:

Just in case someone runs into this...

万一有人遇到这个......

#4


0  

I don't think there's any restriction on this in the spec. Only void elements cannot have children. See http://dev.w3.org/html5/markup/syntax.html#void-element

我不认为规范中对此有任何限制。只有void元素才能生成子元素。请参阅http://dev.w3.org/html5/markup/syntax.html#void-element

A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes.

void元素是一个元素,其内容模型永远不允许它在任何情况下都有内容。 Void元素可以具有属性。

The following is a complete list of the void elements in HTML:

以下是HTML中void元素的完整列表:

area, base, br, col, command, embed, hr, img, input, keygen, link,
meta, param, source, track, wbr

Although generally the h1, h2, h3, etc. would be rendered in a single size. For a sub header like your "(this is your default card)" you might use a smaller header e.g. h4.

虽然通常h1,h2,h3等将以单一尺寸呈现。对于像“(这是您的默认卡片)”这样的子标题,您可以使用较小的标题,例如H4。