gpt4 book ai didi

html - HTML5 主要元素的用途

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:51 24 4
gpt4 key购买 nike

我最近一直在研究 HTML 语义,我想知道 <main> 的真正目的是什么是。我创建了如下所示的两个场景:

场景一

     <main role="main">
<header role="banner">
<hgroup>
<h1>Header 1</h1>
<h2>Header 2</h2>
</hgroup>

<nav>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</nav>
</header>

<section role="region">
<header>
<h1>Articles</h1>
</header>

<article>
<header>
<h1>Article name</h1>
</header>

<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>

<footer>
<a href="#" title="Read more">Read this post</a>
</footer>
</article>

<footer>
<a href="#" title="Read more">Read this articles</a>
</footer>
</section>

<footer role="contentinfo">
<p>Page last updated <time datetime="2009-11-04">November 4th, 2009</time></p>
<address>
<a title="Posts by Just A Name" href="#">Just A Name</a>
</address>
</footer>
</main>

场景二

     <header role="banner">
<hgroup>
<h1>Header 1</h1>
<h2>Header 2</h2>
</hgroup>

<nav>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</nav>
</header>

<main role="main">
<section role="region">
<header>
<h1>Articles</h1>
</header>

<article>
<header>
<h1>Article name</h1>
</header>

<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>

<footer>
<a href="#" title="Read more">Read this post</a>
</footer>
</article>

<footer>
<a href="#" title="Read more">Read this articles</a>
</footer>
</section>
</main>

<footer role="contentinfo">
<p>Page last updated <time datetime="2009-11-04">November 4th, 2009</time></p>
<address>
<a title="Posts by Just A Name" href="#">Just A Name</a>
</address>
</footer>

哪个是最好的解决方案,为什么?

最佳答案

根据 W3C main 应该仅用于该文档独有的内容,因此在您的情况下,方案 #2 是最合适的。

The main element represents the main content section of the body of a document or application. The main content section consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.

Note: the main element is not sectioning content and has no effect on the document outline

The main content section of a document includes content that is unique to that document and excludes content that is repeated across a set of documents such as site navigation links, copyright information, site logos and banners and search forms (unless the document or applications main function is that of a search form).

Authors MUST NOT include more than one main element in a document.

Authors MUST NOT include the main element as a child of an article, aside, footer, header or nav element.

关于html - HTML5 主要元素的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35504679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com