主要内容的 HTML5 语义文章标签

发布于 2024-10-30 05:17:47 字数 396 浏览 2 评论 0原文

语义:您希望它们正确,但有时它们只是令人困惑。

网站文档结构:

<body>
    <header>
    <div id="main">
        <header> (not on every page)
        <div id="content">
        <footer> (not on every page)
    <aside>
    <footer>

div#main 替换为 article< 在语义上是否正确/strong> 标签?

Semantics: You want to get them right but sometimes they're just confusing.

Website document structure:

<body>
    <header>
    <div id="main">
        <header> (not on every page)
        <div id="content">
        <footer> (not on every page)
    <aside>
    <footer>

Is it semantically correct to replace div#main with an article tag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

櫻之舞 2024-11-06 05:17:47

在这个问题上复活死者,目前接受的答案很快就会是错误的。有一个针对

元素的扩展草案,旨在满足您的需求。此外,它还可以在浏览器中自动执行 ARIA role="main",以实现更好的可访问性。请参阅此链接了解更多信息:https://dvcs.w3。 org/hg/html-extensions/raw-file/tip/maincontent/index.html

该规范是 HTML5 规范 [HTML5] 的扩展。它定义了一个用于识别的元素
文档的主要内容区域。中的所有规范内容
HTML5 规范,除非明确被此覆盖
规范,旨在作为本规范的基础。

主要元素形式化了识别的常见做法
使用 id 值的文档的主要内容部分,例如
“内容”和“主要”。它还定义了一个 HTML 元素,其中包含
WAI-ARIA [ARIA] 标志性角色=main 的语义和功能。

<main>

  <h1>Apples</h1>
 <p>The apple is the pomaceous fruit of the apple tree.</p>

 <article>
 <h2>Red Delicious</h2>
  <p>These bright red apples are the most common found in many
  supermarkets.</p>
  <p>... </p>
  <p>... </p>
  </article>

  <article>
  <h2>Granny Smith</h2>
  <p>These juicy, green apples make a great filling for
  apple pies.</p>
  <p>... </p>
  <p>... </p>
  </article>

</main>

To raise the dead on this question, the currently accepted answer will soon be incorrect. There has been an extension draft for a <main> element targeted for exactly what you need. Furthermore it automates the ARIA role="main" in the browser for better accessibility. Please see this link for more info: https://dvcs.w3.org/hg/html-extensions/raw-file/tip/maincontent/index.html

This specification is an extension to the HTML5 specification [HTML5]. It defines an element to be used for the identification of
the main content area of a document. All normative content in the
HTML5 specification, unless specifically overridden by this
specification, is intended to be the basis for this specification.

The main element formalises the common practice of identification of
the main content section of a document using the id values such as
'content' and 'main'. It also defines an HTML element that embodies
the semantics and function of the WAI-ARIA [ARIA] landmark role=main.

<main>

  <h1>Apples</h1>
 <p>The apple is the pomaceous fruit of the apple tree.</p>

 <article>
 <h2>Red Delicious</h2>
  <p>These bright red apples are the most common found in many
  supermarkets.</p>
  <p>... </p>
  <p>... </p>
  </article>

  <article>
  <h2>Granny Smith</h2>
  <p>These juicy, green apples make a great filling for
  apple pies.</p>
  <p>... </p>
  <p>... </p>
  </article>

</main>
长亭外,古道边 2024-11-06 05:17:47

根据 http://html5doctor.com/the-article-element/ 这是一个有效的语义编码方式。它被称为“网络博客风格

”。

根据您的结构,您也可以将 #content 替换为文章。

不要忘记添加 http://code.google.com/p/html5shiv/ 和当您通过 https 为您的网站提供服务时,还要查看协议相关 Url(Google 搜索),这样您就不必检测 http 和 https 之间的切换。

As per http://html5doctor.com/the-article-element/ that is a valid semantic way of coding. It is referred to as "A weblog-style <article>".

Depending on your structure you might be able to replace #content with an article as well.

Do not forget to include http://code.google.com/p/html5shiv/ and while you're at it if you serve your site over https also look into Protocol Relative Url (Google for it), so you don't have to detect the switch between http and https.

恏ㄋ傷疤忘ㄋ疼 2024-11-06 05:17:47

我认为用

标签替换它会更合适。

标签适用于博客文章、论坛帖子或报纸文章等内容(该标签的名称由此而来)。

相反,

标签适用于文档中更通用的内容部分,因此更适合这种情况。

Mark PilgrimDiveIntoHTML5.ep.io

I think it would be more appropriate to replace it with a <section> tag. The <article> tag is meant for stuff like blog posts, forum posts, or newspaper articles (hence the name of the tag).

In contrast, the <section> tag is meant for more generic parts of content in your document and thus is better suited in this case.

This is all much better explained by Mark Pilgrim at DiveIntoHTML5.ep.io

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文