HTML5页脚元素和混乱的w3.org示例
我正在浏览w3.org页面上关于HTML5页脚元素和混乱的w3.org示例,html,footer,semantic-markup,Html,Footer,Semantic Markup,我正在浏览w3.org页面上关于文章元素的内容,其中一个例子让我感到惊讶: <article> <header> <h1>The Very First Rule of Life</h1> <p><time pubdate datetime="2009-10-09T14:28-08:00"></time></p> </header> <p>If there's a
文章
元素的内容,其中一个例子让我感到惊讶:
<article>
<header>
<h1>The Very First Rule of Life</h1>
<p><time pubdate datetime="2009-10-09T14:28-08:00"></time></p>
</header>
<p>If there's a microphone anywhere near you, assume it's hot and
sending whatever you're saying to the world. Seriously.</p>
<p>...</p>
<section>
<h1>Comments</h1>
<article>
<footer>
<p>Posted by: George Washington</p>
<p><time pubdate datetime="2009-10-10T19:10-08:00"></time></p>
</footer>
<p>Yeah! Especially when talking about your lobbyist friends!</p>
</article>
<article>
<footer>
<p>Posted by: George Hammond</p>
<p><time pubdate datetime="2009-10-10T19:15-08:00"></time></p>
</footer>
<p>Hey, you have the same first name as me.</p>
</article>
</section>
</article>
有什么特别的原因吗?这里的经验法则是,
页脚
应该用来标记关于封闭部分的元信息(在您的示例中,每个注释的作者和发布时间)。此外,正如您所注意到的,根据规范,页脚不一定必须位于节的“底部”
相反,标题
用于封闭部分的介绍性内容,应至少包含一个标题元素。事实上,我认为排除heading元素是原始示例使用footer
元素的主要原因
为了避免混淆,这并不意味着每个标题都应该包装在标题中,因为在这种情况下,它不会添加任何语义值
所以一般的经验法则是:如果它有标题和一些附加信息(副标题、pubdate、TOC、nav…),那么它通常可以包含在标题中。关于章节的任何附加信息/元数据,如果没有出现在文档流的标题附近(脚注、相关链接、自动信息、版权等),可以包含在footer
中
参考资料:
-
-和之间的语义差异并不总是很清楚。在不清楚的情况下,重要的是你使用其中一个,而不是使用哪一个
页脚和页眉的位置
位置不重要(只要它在相关部分内)。由于标题
用于介绍性内容,因此它通常会出现在本节顶部附近。对于页脚
,规范说明:
页脚不一定要出现在节的末尾,尽管它们通常会出现
这甚至是可能的(并非一定是个好主意):
(“有关父文档的信息”)
标题
包含(“主要面向站点的内容,而不是特定于页面的内容”)
<section>
<h1>Comments</h1>
<article>
<header>
<p>Posted by: George Washington</p>
<p><time pubdate datetime="2009-10-10T19:10-08:00"></time></p>
</header>
<p>Yeah! Especially when talking about your lobbyist friends!</p>
</article>
<article>
<header>
<p>Posted by: George Hammond</p>
<p><time pubdate datetime="2009-10-10T19:15-08:00"></time></p>
</header>
<p>Hey, you have the same first name as me.</p>
</article>
</section>