美好的一天,
我刚开始学习 HTML5 - 没有问题,一切都很顺利。
关于 <article>
的语义用法,我只有一个小问题, <section>
和 <div>
标签。
我知道 <div>
元素没有语义意义——在 HTML5 中它应该主要用于脚本/样式目的。在这里,一切对我来说都很清楚。我在 SO 问题中发现了很多有用的信息:HTML5 has new tags article, section and aside. When should I use div tag? .
但是,我对 <article>
有一些问题和 <section>
用法。 W3C HTML5 规范说 <article>
标签
Specifies independent, self-contained content, could be a news-article, blog post, forum post, or other articles which can be distributed independently from the rest of the site.
哪里<section>
应该使用标签
For a section in a document. Such as chapters, headers, footers, or any other sections of the document.
理论上,一切都很清楚。然而,在为我的第一个 HTML5 网站准备代码时,我发现很难区分。
让我解释一下我的网站结构:
- 背景被添加到正文元素中。工作完美。
- 我使用 960.gs我的每个 HTML/CSS 项目中的网格系统。这次我也在用。您肯定知道,它需要添加一个容器(在我的例子中有一个类:container_12)。
结束对我的结构的解释:
- 作为主容器,我使用了
<div class="container_12">
- 我文档中的第一个元素是
<header>
.它包含几个元素: slider 和顶栏。顶部栏是<section>
.它有两个子元素:左边的电话号码和右边的语言列表。对于这些元素,我使用了<section>
也。对于 slider (或内页上的简短标语占位符),我使用了<section>
包含两个<section>
的标签标签:左右栏。 - 作为主页的主要内容包装器,我决定使用
<section>
元素。对于内页,我使用<article>
对于“关于我们”等页面。对于博客列表,我使用<section>
列表为<article>
里面的标签。对于单个帖子,我使用<article>
元素。 - 显然,对于页脚,我使用
<footer>
元素与三个<section>
元素作为列包装器。
转换为 HTML5 之前的布局:
<div class="container_12">
<div class="grid_12 header">
<div class="bar grid_12 alpha omega">
<div class="grid_6 alpha">
Phone number
</div>
<div class="grid_6 omega">
German - English - French
</div>
</div>
<div class="grid_6 alpha">
LOGOTYPE
</div>
<div class="grid_6 omega">
<ul>
navigation
</ul>
</div>
<div class="grid_12 alpha omega">
<div class="grid_6 alpha">
Slider I col
</div>
<div class="grid_6 omega">
Slider II col
</div>
</div>
</div>
<div class="grid_12 content">
</div>
<div class="grid_12 footer">
<div class="grid_4 alpha">
Footer I col
</div>
<div class="grid_4">
Footer II col
</div>
<div class="grid_4 omega">
Footer III col
</div>
</div>
</div>
这是我将其转换为 HTML5 后的代码:
<div class="container_12">
<header class="grid_12">
<section class="bar grid_12 alpha omega">
<section class="grid_6 alpha">
Phone number
</section>
<section class="grid_6 omega">
German - English - French
</section>
</section>
<section class="grid_6 alpha">
LOGOTYPE
</section>
<nav class="grid_6 omega">
<ul>
navigation
</ul>
</nav>
<section class="grid_12 alpha omega">
<section class="grid_6 alpha">
Slider I col
</section>
<section class="grid_6 omega">
Slider II col
</section>
</section>
</header>
<section class="grid_12 content">
</section>
<footer class="grid_12">
<section class="grid_4 alpha">
Footer I col
</section>
<section class="grid_4">
Footer II col
</section>
<section class="grid_4 omega">
Footer III col
</section>
</footer>
</div>
我的做法是否正确?您可以添加或更正一些内容吗?
为了避免任何问题:我知道 <section>
不能替代 <div>
.
最佳答案
嗯,回答这个问题的一种方法是使用类似 http://gsnedders.html5.org/outliner/ 的工具查看文档的大纲。 .你会注意到每个部分都需要一个标题才能有意义,所以如果没有一些内容就很难说。如果每个部分都有一个 H!有意义的标签,那么它通常是正确的。如果一个部分不需要 h1,那么它通常是错误的。
章节本身应该有意义,没有上下文。理解这一点的一种简单方法是考虑 RSS 提要 - 提要中的每个条目就像一个部分。如果您将它添加到 RSS 提要(或者它在那种情况下有意义),那么它可能是一个部分。如果它只是页脚上的一列,那么您不会将其放在 RSS 提要中,因此它可能不是一个部分。
基于此,我可能会做这样的事情(基于我对您在每一位中放入的内容的假设)。我还添加了 WAI-ARIA 地标角色,因为它们很简单,并且在您使用屏幕阅读器时会产生很大的不同。
<div class="container_12">
<header class="grid_12" role="banner">
<div class="bar grid_12 alpha omega">
<div class="grid_6 alpha">
Phone number
</div>
<div class="grid_6 omega">
German - English - French
</div>
</div>
<div class="grid_6 alpha">
LOGOTYPE
</div>
<nav class="grid_6 omega" role="navigation">
<ul>
navigation
</ul>
</nav>
<div class="grid_12 alpha omega">
<div class="grid_6 alpha">
Slider I col
</div>
<div class="grid_6 omega">
Slider II col
</div>
</div>
</header>
<section class="grid_12 content" role="main">
<!-- Not sure what goes in here? Let's assume it's the main content. -->
</section>
<footer class="grid_12">
<div class="grid_4 alpha">
Footer I col
</div>
<div class="grid_4">
Footer II col
</div>
<div class="grid_4 omega">
Footer III col
</div>
</footer>
</div>
关于HTML5 结构 - <article>、<section> 和 <div> 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8734350/
-
cookies - 移动应用程序 - Cookie 法
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
-
java - 实体惰性方法和 Dimetra 法
我有实体: @Entity @Table(name = "CARDS") public class Card { @ManyToOne @JoinColumn(name = "PERSON_I
-
javascript - 计算多边形的法向量 - Newells 法
我正在尝试计算二维多边形的表面法线。我正在使用 OpenGL wiki 中的 Newell 方法来计算表面法线。 https://www.opengl.org/wiki/Calculating_a_S
-
jquery - 着陆页上的谷歌分析代码和 cookie 法
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
-
android - 移动应用程序是否需要遵守欧盟 Cookie 法?
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
-
ruby - Nokogiri child 法
我这里有以下 XML: Visa, Mastercard, , , , 0, Discover, American Express siteonly, Buyer Pay
-
Android - 欧盟 Cookie 法
即将发生的 Google 政策变更迫使我们实现一个对话框,以通知欧盟用户有关 Cookie/设备标识符用于广告和分析的情况。我只想向欧盟用户显示此对话框。我不想使用额外的权限(例如 android.p
-
华为云大咖说:开发者应用AI大模型的“道、法、术”
本文分享自华为云社区《华为大咖说 | 企业应用AI大模型的“道、法、术” ——道:认知篇》,作者:华为云PaaS服务小智。 本期核心观点 上车:AGI是未来5~10年内,每个人都无法回避的技
-
asp.net - 关于年龄验证的 Cookie 法
我有一个与酒精相关的网站,需要先验证年龄,然后才能让他们进入该网站。我使用 HttpModule 来执行此操作,该模块检查 cookie,如果未设置,我会将它们重定向到验证页面。我验证他们的年龄并存储
-
javascript - 自动选择加入 cookie 的浏览器插件 - 欧盟 cookie 法
在欧盟,我们有一项法律,要求网页请求存储 cookie 的许可。我们大多数人都了解 cookie 并同意它们,但仍然被迫在任何地方明确接受它们。所以我计划编写这个附加组件(ff & chrome),它
-
c++ - 在 C/C++ 中声明函数然后定义它是否内 union 法?
以下在 C 和/或 C++ 中是否合法? void fn(); inline void fn() { /*Do something here*/ } 让我担心的是,第一个声明看起来暗示函数将被定义
我是一名优秀的程序员,十分优秀!