我有兴趣了解更多关于 HTML5 <main>
之间的关系和可能的区别。元素和 ARIA 地标角色属性 role="main"
.
我的印象是 <main>
的目的元素是映射 ARIA 滚动属性 role="main"
到特定的 HTML 元素上。但这就是总结吗?
使用 <main>
有什么好处吗?比方说,<div role="main">
?或者,在现在和可预见的 future ,这些会产生相同的结果吗?
如果能对以下示例进行比较,我们将不胜感激:
<body>
<main>
<p>Paragraph</p>
<main>
</body>
<body>
<main role="main">
<p>Paragraph</p>
<main>
</body>
<body>
<div role="main">
<p>Paragraph</p>
<div>
</body>
最佳答案
根据 HTML5 Doctor,它们是等价的。 <main>
只是让实现变得更容易和更整洁 role="main"
.
The primary purpose of is to map ARIA’s landmark role main to an element in HTML.
这里是对 <main>
的一般描述元素。
The
main
element represents the main content of thebody
of a document or application. The main content area consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.
推荐
建议同时使用 <main>
和 role="main"
在同一元素中,直到浏览器实现 <main>
<!-- Recommended -->
<main role="main">
...
</main>
请务必阅读 <main>
spec如果你有兴趣。
切片注意事项
正如 Szabolcs 在评论中指出的那样,<main>
不是分段元素,因此应与 <section>
结合使用元素。
引用资料
关于HTML5 主要元素与 ARIA 地标角色 ="main",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19595719/