关于 <article> 的 <footer> 元素的出现顺序在 HTML5 中是否重要?
Does the order of appearance of a <footer> element in regard to <article> matter in HTML5?
在我正在处理的页面上,我注意到以下模式:
<section>
<header>Article Headline</header>
<footer>
<!-- publication date and author go here -->
</footer>
<article>
<!-- article content goes here -->
</article>
</section>
乍一看,<footer>
元素出现在<article>
之前,让我有点意外(我是后端开发,HTML技能没磨练过尽可能多)。当被问到这个问题时,我的同事只是说这里使用的顺序使样式更容易,在涉及语义时可能很好,而且顺序并不重要,但无法为我指出明确的来源。
我试图找到一些关于 <footer>
标签语义的信息,似乎关于管理其允许内容的规则或它作为另一个标签的子标签的外观的规则可以说很多(我发现description on MDN 特别好和清晰)但是几乎没有关于排序的信息。
我找到的唯一提到 <footer>
顺序的是 W3C specification for HTML5
Footers don't necessarily have to appear at the end of a section, though they usually do.
根据这些资料,在我看来,除了解释得很好的父子关系之外,确实没有规则指定 <article>
和 <footer>
之间的任何关系。因此,我的 post 开头的标记在语义上是正确的,如果它用于其他目的,我们确实可以随意对这些元素重新排序。
这个假设是否正确?还有其他需要注意的注意事项吗?
是的,您的评估是正确的。页脚将始终是页脚,无论它出现在其分节元素中的确切位置,只要它出现在其预期的正确分节元素中即可。页脚的唯一区别特征是出现在其中的内容类型,正如规范所建议的那样,可能是:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
When the footer
element contains entire sections, they represent appendices, indexes, long colophons, verbose license agreements, and other such content.
正如§4.3.8 The footer element所说,
The footer
element represents a footer for its nearest ancestor
sectioning content or sectioning root element.
所以您可以自由移动它(如果不改变它的部分)而不改变它的语义:作为该部分的页脚。
在我正在处理的页面上,我注意到以下模式:
<section>
<header>Article Headline</header>
<footer>
<!-- publication date and author go here -->
</footer>
<article>
<!-- article content goes here -->
</article>
</section>
乍一看,<footer>
元素出现在<article>
之前,让我有点意外(我是后端开发,HTML技能没磨练过尽可能多)。当被问到这个问题时,我的同事只是说这里使用的顺序使样式更容易,在涉及语义时可能很好,而且顺序并不重要,但无法为我指出明确的来源。
我试图找到一些关于 <footer>
标签语义的信息,似乎关于管理其允许内容的规则或它作为另一个标签的子标签的外观的规则可以说很多(我发现description on MDN 特别好和清晰)但是几乎没有关于排序的信息。
我找到的唯一提到 <footer>
顺序的是 W3C specification for HTML5
Footers don't necessarily have to appear at the end of a section, though they usually do.
根据这些资料,在我看来,除了解释得很好的父子关系之外,确实没有规则指定 <article>
和 <footer>
之间的任何关系。因此,我的 post 开头的标记在语义上是正确的,如果它用于其他目的,我们确实可以随意对这些元素重新排序。
这个假设是否正确?还有其他需要注意的注意事项吗?
是的,您的评估是正确的。页脚将始终是页脚,无论它出现在其分节元素中的确切位置,只要它出现在其预期的正确分节元素中即可。页脚的唯一区别特征是出现在其中的内容类型,正如规范所建议的那样,可能是:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
When the
footer
element contains entire sections, they represent appendices, indexes, long colophons, verbose license agreements, and other such content.
正如§4.3.8 The footer element所说,
The
footer
element represents a footer for its nearest ancestor sectioning content or sectioning root element.
所以您可以自由移动它(如果不改变它的部分)而不改变它的语义:作为该部分的页脚。