<main>
是否应该被视为放置在<section>
内的重要内容?比如将许多带有<main>
“文章”的<section>
放在一起?如果不是,则如何将它们组合使用?
<main>
是否应该被视为放置在<section>
内的重要内容?比如将许多带有<main>
“文章”的<section>
放在一起?如果不是,则如何将它们组合使用?
根据HTML5规范:
作者不能在文档中包含多个主要元素。
作者不得将主要元素作为article、aside、footer、header或nav元素的后代。
主要元素表示文档或应用程序主体内容。
因此,您应该使用main作为网站主体内容的分隔符,并在main内部使用article或sections作为上下文的分隔符。以下是如何处理main的示例:
<main>
<h1>Skateboards</h1>
<p>The skateboard is the way cool kids get around</p>
<article>
<h2>Longboards</h2>
<p>Longboards are a type of skateboard with a longer
wheelbase and larger, softer wheels.</p>
<p>... </p>
<p>... </p>
</article>
<article>
<h2>Electric Skateboards</h2>
<p>These no longer require the propelling of the skateboard
by means of the feet; rather an electric motor propels the board,
fed by an electric battery.</p>
<p>... </p>
<p>... </p>
</article>
</main>
引用HTML5规范:
建议作者在主要元素上使用ARIA role="main"属性,直到用户代理实现所需的角色映射。
HTML5 Doctor,虽然有点过时,但提供了一个有用的main
元素工作示例:
<main id="content" class="group">
<!-- [...] -->
</main>
main
元素(但每个页面只能使用一次)。或者,您可以在分区元素上使用role="main"
,在WAI-ARIA方面具有完全相同的结果。在我的文章中阅读更多关于WAI-ARIA角色的内容。例如:<div class="main-content-column">
<article role="main" id="content">
[...]
</article>
</div>
role="main"
分配给section
元素会有任何语义上的意义,但可能有用例。一般来说,您应该使用article
标记来识别main
内容。上面的代码片段提供了与<main>
完全相同的语义信息(请注意,在现代屏幕阅读器和用户代理中,不需要在<main>
元素上声明role="main"
)。主要标签应该用于页面上的主要内容。
部分
。” - unor