html5 页面结构

The following is an extract from our book, HTML5 & CSS3 for the Real World, 2nd Edition, written by Alexis Goldstein, Louis Lazaris, and Estelle Weyl. Copies are sold in stores worldwide, or you can buy it in ebook form here.

以下摘自Alexis Goldstein,Louis Lazaris和Estelle Weyl编写的《现实世界HTML5和CSS3,第二版 》一书。 副本在世界各地的商店中都有出售,或者您可以在此处以电子书形式购买 。

Now that we’ve broken down the basics of our template, let’s start adding some meat to the bones and give our page some structure.

现在,我们已经分解了模板的基础知识,让我们开始向骨骼添加一些肉,并为页面提供一些结构。

Later in the book, we’re going to specifically deal with adding CSS3 features and other HTML5 goodness; for now, we’ll consider what elements we want to use in building our site’s overall layout. We’ll be covering a lot in this section and throughout the coming chapters about semantics. When we use the term “semantics,” we’re referring to the way a given HTML element describes the meaning of its content.

在本书的后面,我们将专门处理添加CSS3功能和其他HTML5优点。 现在,我们将考虑在构建网站的整体布局时要使用哪些元素。 在本节以及接下来的有关语义的各章中,我们将涉及很多内容。 当我们使用“语义”一词时,是指给定HTML元素描述其内容含义的方式。

If you look back at the screenshot of The HTML5 Herald (or view the site online), you’ll see that it’s divided up as follows:

如果回头看HTML5 Herald的屏幕截图(或在线查看网站),您会发现它的划分如下:

  • header section with a logo and title

    标头部分带有徽标和标题

  • navigation bar

    导航栏

  • body content divided into three columns

    正文内容分为三列

  • articles and ad blocks within the columns

    列中的文章和广告块

  • footer containing some author and copyright information

    页脚包含一些作者和版权信息

Before we decide which elements are appropriate for these different parts of our page, let’s consider some of our options. First of all, we’ll introduce you to some of the new HTML5 semantic elements that could be used to help divide our page and add more meaning to our document’s structure.

在决定哪些元素适合页面的这些不同部分之前,让我们考虑一些选项。 首先,我们将向您介绍一些新HTML5语义元素,这些元素可用于帮助划分页面并为文档的结构添加更多含义。

header元素 (The header Element)

Naturally, the first element we’ll look at is the header element. The spec describes it succinctly as “a group of introductory or navigational aids.”

自然,我们要看的第一个元素是header元素。 该规范将其简洁地描述为“一组入门或导航辅助工具”。

Contrary to what you might normally assume, you can include a new header element to introduce each section of your content. It’s not just reserved for the page header (which you might normally mark up with <div id="header">). When we use the word “section” here, we’re not limiting ourselves to the actual section element described in the next part; technically, we’re referring to what HTML5 calls “sectioning content.” This means any chunk of content that might need its own header, even if that means there are multiple such chunks on a single page.

与通常的假设相反,您可以包括一个新的header元素以介绍内容的每个部分。 它不只是保留给页面标题(通常可以用<div id="header">标记)。 当我们在此处使用“ section”一词时,我们并不局限于下一部分中描述的实际section元素; 从技术上讲,我们指的是HTML5所谓的“分段内容”。 这意味着可能需要其自己的标头的任何内容块,即使这意味着在单个页面上存在多个此类块。

A header element can be used to include introductory content or navigational aids that are specific to any single section of a page, or apply to the entire page, or both.

header元素可用于包括介绍性内容或特定于页面任何部分的导航帮助,或应用于整个页面,或两者。

While a header element will frequently be placed at the top of a page or section, its definition is independent from its position. Your site’s layout might call for the title of an article or blog post to be off to the left, right, or even below the content; regardless of which, you can still use header to describe this content.

尽管header元素通常会放置在页面或节的顶部,但其定义与位置无关。 您网站的布局可能要求文章或博客文章的标题位于内容的左侧,右侧甚至下方。 无论哪个,您仍然可以使用header来描述此内容。

section元素 (The section Element)

The next element you should become familiar with is HTML5’s section element. The spec defines section as follows:

您应该熟悉的下一个元素是HTML5的section元素。 规范定义了以下section

The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.

section元素代表文档或应用程序的通用部分。 在这种情况下,一节是内容的主题分组,通常带有标题。

It further explains that a section shouldn’t be used as a generic container that exists for styling or scripting purposes only. If you’re unable to use section as a generic container—for example, in order to achieve your desired CSS layout—then what should you use? Our old friend, the div element, which is semantically meaningless.

它进一步说明,不应将某section用作仅用于样式或脚本编写目的的通用容器。 如果您无法将section用作通用容器(例如,为了实现所需CSS布局),那么应该使用什么? 我们的老朋友div元素在语义上是没有意义的。

Going back to the definition from the spec, the section element’s content should be “thematic,” so it would be incorrect to use it in a generic way to wrap unrelated pieces of content.

回到规范的定义, section元素的内容应为“主题”,因此以通用方式包装不相关的内容是不正确的。

Some examples of acceptable uses for section elements include:

section元素可接受用途的一些示例包括:

  • individual sections of a tabbed interface

    选项卡式界面的各个部分

  • segments of an “About” page; for example, a company’s “About” page might include sections on the company’s history, its mission statement, and its team

    “关于”页面的各个部分; 例如,公司的“关于”页面可能包含有关公司历史,任务说明和团队的部分

  • different parts of a lengthy “terms of service” page

    冗长的“服务条款”页面的不同部分

  • various sections of an online news site; for example, articles could be grouped into sections covering sports, world affairs, and economic news

    在线新闻站点的各个部分; 例如,文章可以分为体育,世界事务和经济新闻等部分

注意:正确使用section (Note: Using section Correctly)

Every time new semantic markup is made available to web designers, there will be debate over what constitutes correct use of these elements, what the spec’s intention was, and so on. You may remember discussions about the appropriate use of the dl element in previous HTML specifications. Unsurprisingly, HTML5 has not been immune to this phenomenon, particularly when it comes to the section element. Even Bruce Lawson, a well-respected authority on HTML5, has admitted to using section incorrectly in the past. For a bit of clarity, it’s well worth reading Bruce’s post explaining his error.

每次将新的语义标记提供给Web设计人员时,都会就什么构成这些元素的正确使用,规范的意图等问题进行辩论。 您可能还记得在以前HTML规范中有关dl元素的适当用法的讨论。 毫不奇怪,HTML5不能幸免于这种现象,特别是在涉及section元素时。 甚至著名HTML5权威布鲁斯·劳森(Bruce Lawson)也承认过去错误地使用了section 。 为了清楚起见,值得阅读Bruce的文章来解释他的错误。

In short:

简而言之:

  • section is generic, so if a more specific semantic element is appropriate (such as article, aside, or nav), use that instead.

    section通用的 ,因此如果更具体的语义元素是适当的(例如articleasidenav ),请改用它。

  • section has semantic meaning; it implies that the content it contains is related in some way. If you’re unable to succinctly describe all the content you’re trying to put in a section using just a few words, it’s likely you need a semantically neutral container instead: the humble div.

    section 具有语义 ; 它暗示其中包含的内容以某种方式相关。 如果您无法仅用几句话就简洁地描述您要放在一section中的所有内容,则可能需要一个语义上中立的容器:humble div

That said, as is always the case with semantics, it’s open to interpretation in some instances. If you feel you can make a case for why you’re using a given element rather than another, go for it. In the unlikely event that anyone ever calls you on it, the resulting discussion can be both entertaining and enriching for everyone involved, and might even contribute to the wider community’s understanding of the specification.

就是说,就像语义学一样,它在某些情况下是开放的。 如果您觉得可以说明为什么要使用给定元素而不是另一个,请继续尝试。 万一有人向您提出要求,那么最终的讨论可能会为所涉及的每个人带来娱乐和丰富,甚至可能有助于更广泛的社区对规范的理解。

Keep in mind, also, that you’re permitted to nest section elements inside existing section elements, if it’s appropriate. For example, for an online news website, the World News section might be further subdivided into a section for each major global region.

另外请记住,如果合适的话,也可以将section元素嵌套在现有section元素中。 例如,对于在线新闻网站,“世界新闻”部分可能会进一步细分为每个主要全球区域的部分。

article元素 (The article Element)

The article element is similar to the section element, but there are some notable differences. Here’s the definition according to the spec:

article元素与section元素相似,但有一些显着差异。 这是根据规范的定义:

The article element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication.

文章元素表示文档,页面,应用程序或站点中的完整或独立的组成,并且原则上可以独立分发或重用,例如在联合组织中。

The key terms in that definition are self-contained composition and independently distributable. Whereas a section can contain any content that can be grouped thematically, an article must be a single piece of content that can stand on its own. This distinction can be hard to wrap your head around, so when in doubt, try the test of syndication: if a piece of content can be republished on another site without being modified, or if it can be pushed out as an update via RSS, or on social media sites such as Twitter or Facebook, it has the makings of an article.

该定义中的关键术语是独立的组成部分 ,可以独立分配section可以包含可以按主题进行分组的任何内容,而article必须是可以独立存在的单个内容。 这种区别可能很难让人your目结舌,因此,在有疑问时,请尝试进行联合测试:如果可以在不做任何修改的情况下将某段内容重新发布到另一个网站上,或者可以通过RSS将其作为更新发布,或在Twitter或Facebook之类的社交媒体网站上,都有article

Ultimately, it’s up to you to decide what constitutes an article, but here are some suggestions in line with recommendations in the spec:

最终,由您决定文章的构成,但以下是一些与规范中的建议一致的建议:

  • a forum post

    论坛帖子

  • a magazine or newspaper article

    杂志或报纸上的文章

  • a blog entry

    博客条目

  • a user-submitted comment on a blog entry or article

    用户对博客条目或文章的评论

Finally, just like section elements, article elements can be nested inside other article elements. You can also nest a section inside an article, and vice versa. It all depends on the content you’re marking up.

最后,就像section元素一样, article元素可以嵌套在其他article元素内。 您也可以在article嵌套一个section ,反之亦然。 这完全取决于您要标记的内容。

nav元素 (The nav Element)

It’s safe to assume that the nav element will appear in virtually every project. nav represents exactly what it implies: a group of navigation links. Although the most common use for nav will be for wrapping an unordered list of links, there are other options. For example, you could wrap the nav element around a paragraph of text that contained the major navigation links for a page or section of a page.

可以肯定地认为nav元素几乎会出现在每个项目中。 nav精确地表示了它的含义:一组导航链接。 尽管nav最常见的用途是包装无序链接列表,但还有其他选择。 例如,您可以将nav元素包裹在一段文本中,该文本段落包含页面或页面部分的主要导航链接。

In either case, the nav element should be reserved for navigation that is of primary importance. So, it’s recommended that you avoid using nav for a brief list of links in a footer, for example.

无论哪种情况,都应保留nav元素用于最重要的导航。 因此,建议您避免在页脚中使用简短的链接列表来使用nav

注意:跳过导航链接 (Note: Skip Navigation Links)

A design pattern you may have seen implemented on many sites is the “skip navigation” link. The idea is to allow users of screen readers to quickly skip past your site’s main navigation if they’ve already heard it—after all, there’s no point listening to a large site’s entire navigation menu every time you click through to a new page! The nav element has the potential to eliminate this need; if a screen reader sees a nav element, it could allow its users to skip over the navigation without requiring an additional link. The specification states: “User agents (such as screen readers) that are targeted at users who can benefit from navigation information being omitted in the initial rendering, or who can benefit from navigation information being immediately available, can use this element as a way to determine what content on the page to initially skip or provide on request (or both).”

您可能已经在许多站点上看到的一种设计模式是“跳过导航”链接。 这样做的目的是让屏幕阅读器的用户已经听说过站点的主要导航功能时,可以快速跳过它们。毕竟,每次单击新页面时,都没有必要聆听大型站点的整个导航菜单! nav元素有可能消除这种需求; 如果屏幕阅读器看到nav元素,则可以允许其用户跳过导航而无需其他链接。 该规范指出:“针对可以从初始渲染中省略的导航信息中受益或可以从导航信息立即可用中受益的用户的用户代理(例如屏幕阅读器)可以使用此元素作为一种方式确定页面上哪些内容最初应跳过或应要求提供(或同时提供)。”

Although not all assistive devices recognize nav as of this writing, by building to the standards now you ensure that as screen readers improve, your page will become more accessible over time.

尽管在撰写本文时,并不是所有的辅助设备都可以识别nav ,但通过现在建立标准,您可以确保随着屏幕阅读器的改进,随着时间的推移,您的页面将变得更加可访问。

注意:用户代理 (Note: User Agents)

You’ll encounter the term “user agent” a lot when browsing through specifications. Really, it’s just a fancy term for a browser—a software “agent” that a user employs to access the content of a page. The reason the specs don’t simply say “browser” is that user agents can include screen readers or any other technological means to read a web page.

浏览规范时,您会经常遇到“用户代理”一词。 实际上,这只是浏览器的一个奇特术语,即用户用来访问页面内容的软件“代理”。 规范没有简单地说“浏览器”的原因是用户代理可以包括屏幕阅读器或任何其他技术手段来读取网页。

You can use nav more than once on a given page. If you have a primary navigation bar for the site, this would call for a nav element. Additionally, if you had a secondary set of links pointing to different parts of the current page (using in-page anchors or “local” links), this too could be wrapped in a nav element.

您可以在给定页面上多次使用nav 。 如果您有该站点的主导航栏,则需要一个nav元素。 另外,如果您有一组指向当前页面不同部分的辅助链接(使用页面内定位符或“本地”链接),则也可以将其包装在nav元素中。

As with section, there’s been some debate over what constitutes acceptable use of nav and why it isn’t recommended in some circumstances (such as in a footer). Some developers believe this element is appropriate for pagination or breadcrumb links, or for a search form that constitutes a primary means of navigating a site (as is the case on Google).

与本section ,对于什么才是可接受的nav用途以及为什么在某些情况下(例如在页脚中)不推荐使用nav ,存在一些争论。 一些开发人员认为,此元素适用于分页或面包屑链接,或构成构成网站导航的主要方式的搜索表单(例如Google)。

This decision will ultimately be up to you, the developer. Ian Hickson, the primary editor of WHATWG’s HTML5 specification, responded to the question directly: “use [it] whenever you would have used class=nav”.[7]

这个决定最终将取决于您,开发人员。 WHATWG HTML5规范的主要编辑者伊恩·希克森(Ian Hickson)直接回答了这个问题:“只要您使用class = nav,就使用[it]”。 [7]

aside元素 (The aside Element)

This element represents a part of the page that’s “tangentially related to the content around the aside element, and which could be considered separate from that content.”

此元素表示页面的一部分,该部分“与aside元素周围的内容切向相关,并且可以认为与该内容分开”。

The aside element could be used to wrap a portion of content that is tangential to:

aside元素可用于包装与以下内容相切的一部分内容:

  • a specific standalone piece of content (such as an article or section).

    特定的独立内容(例如articlesection )。

  • an entire page or document, as is customarily done when adding a sidebar to a page or website.

    整个页面或文档,就像在页面或网站上添加侧栏时通常所做的那样。

The aside element should never be used to wrap sections of the page that are part of the primary content; in other words, aside is not meant to be parenthetical. The aside content could stand on its own, but it should still be part of a larger whole.

不应使用aside元素来包装页面的主要内容部分。 换句话说, aside并不意味着括号。 aside内容可以独立存在,但仍应是较大整体的一部分。

Some possible uses for aside include a sidebar, a secondary list of links, or a block of advertising. It should also be noted that the aside element (as in the case of header) is not defined by its position on the page. It could be on the side, or it could be elsewhere. It’s the content itself, and its relation to other elements, that defines it.

aside一些可能用途包括侧边栏,链接的辅助列表或广告块。 还应注意, aside元素(如header的情况)不是由其在页面上的位置定义的。 它可以在侧面,也可以在其他地方。 定义内容的是内容本身及其与其他元素的关系。

footer元素 (The footer Element)

The final element we’ll discuss in this chapter is the footer element. As with header, you can have multiple footer elements on a single page, and you should use footer instead of something generic such as <div id="footer">.

我们将在本章中讨论的最后一个元素是footer元素。 与header ,您可以在一个页面上有多个footer元素,并且应该使用footer而不是诸如<div id="footer">通用名称。

A footer element, according to the spec, represents a footer for the section of content that is its nearest ancestor. The section of content could be the entire document, or it could be a section, article, or aside element.

根据规范,页脚元素表示内容部分的页脚,即它的最接近的祖先。 内容部分可以是整个文档,也可以是sectionarticleaside元素。

Often a footer will contain copyright information, lists of related links, author information, and similar information that you normally think of as coming at the end of a block of content; however, much like aside and header, a footer element is not defined in terms of its position on the page, so it does not have to appear at the end of a section, or at the bottom of a page. Most likely it will, but this is not required. For example, information about the author of a blog post might be displayed above the post instead of below it, and will still be considered footer information.

footer通常会包含版权信息,相关链接列表,作者信息以及您通常认为位于内容块末尾的类似信息; 但是,就像asideheader ,footer元素并不是根据其在页面上的位置来定义的,因此它不必出现在节的末尾或页面的底部。 很有可能会这样做,但这不是必需的。 例如,有关博客文章作者的信息可能显示在该文章的上方而不是下方,并且仍被视为页脚信息。

注意:我们如何到达这里? (Note: How did we get here?)

If you’re wondering a little bit about the path to HTML5 and how we ended up with the tags that we did, you might want to check out Luke Stevens’ book called The Truth about HTML5. Currently in its 2nd edition, Luke’s book is somewhat controversial. In addition to covering many of the HTML5 technologies such as video and canvas, he also goes in-depth in his coverage of the history of HTML5, explaining some of the semantic and accessibility problems inherent in the new elements and providing some recommendations on how to handle these issues.

如果您对HTML5的路径以及我们如何获得所使用的标签感到有些疑问,您可能想看看Luke Stevens的书《关于HTML5的真相》 。 目前在第二版中,卢克的书颇具争议。 除了涵盖视频和画布等许多HTML5技术之外,他还深入介绍了HTML5的历史,解释了新元素中固有的一些语义和可访问性问题,并提供了有关如何处理这些问题。



[7] See http://html5doctor.com/nav-element/#comment-213.

[7]参见http://html5doctor.com/nav-element/#comment-213。

翻译自: https://www.sitepoint.com/defining-the-sample-sites-page-structure/

html5 页面结构

html5 页面结构_HTML5页面结构基础相关推荐

  1. wordpress page显示未找到页面_通过Avada主题了解网页基本结构和页面布局

    Avada主题是目前很流行的国外建站主题,我们在学习 avada主题建站初期有必要先了解网页基本结构和页面布局情况,这样对后面使用 avada主题建站,了解 avada主题Theme Options设 ...

  2. c语言 结构体映射,内存管理之4:页面映射中的结构体

    date: 2014-09-10 19:09 备注:本文中引用的内核代码的版本是2.4.0. 在前面的文章中,我们介绍了linux页式内存管理,讲到了页面目录PGD.中间目录PMD以及页表PT,本文来 ...

  3. android页面布局4*4乘法表,day4(分支结构,循环结构,for循环,九九乘法表)

    一:复习 ''' 1.变量名命名规范 -- 1.只能由数字.字母 及 _ 组成 -- 2.不能以数字开头 -- 3.不能与系统关键字重名 -- 4._开头有特殊含义 -- 5.__开头__结尾的变量, ...

  4. 微信小程序页面布局——上中下结构

    小程序页面布局--上中下结构 内容简述 上中下结构:头脚固定+中间滚动框 使用UI框架:Vant Weapp(引入安装参考) 为了方便,使用了less生成wxss,所以展示的是less代码,有需要可以 ...

  5. HTML5文档结构主体结构 语义结构,html5组织文档结构.pdf

    html5组织文档结构 1 / 10 html5 组织文档结构 文档部分,即 body 部分,包含了访问者可以看到的内容.传统的 HTML 文档通常通过 div 元素来组织文档结构,再配 上适当的样式 ...

  6. 自动滚放的html,HTML5实现视频播放器随页面滚动固定页面右下角效果详解

    简要教程 这是一款可以自动将HTML5视频播放器在页面向下滚动时,将其固定在页面右下角位置的jquery和CSS3效果. 使用方法 在页面中引入jquery文件. HTML结构 使用一个 元素来包裹H ...

  7. python异常处理_Python基础语法案例(Fibonacci):选择结构、循环结构、异常处理结构、代码优化...

    推荐图书: <Python程序设计基础(第2版)>,ISBN:9787302490562,董付国,清华大学出版社,第16次印刷,清华大学出版社2019年度畅销图书 图书购买链接(京东):配 ...

  8. Python基础语法案例(Fibonacci):选择结构、循环结构、异常处理结构、代码优化

    推荐图书: <Python程序设计基础(第2版)>,ISBN:9787302490562,董付国,清华大学出版社,第16次印刷,清华大学出版社2019年度畅销图书 图书购买链接(京东): ...

  9. html5 移动端单页面布局

    序      移动端的web网页使用的是响应式设计,但一般我们看到的网站页面都是跳转刷新得到的,比如通过点击一个menu后进入到另一个页面 今天来说下是移动端的单页面的布局.单页面就是一切操作和布局都 ...

最新文章

  1. 一步一步写算法(之hash表)
  2. 在RHEL 5中Yum应用大全
  3. [云炬创业基础笔记] 第四章测试12
  4. 二十六、深入Python中的time和datetime模块
  5. python pytest setupclass_简单了解pytest测试框架setup和tearDown
  6. 上帝就在机器里:复杂算法背后隐藏的可怕现实
  7. hadoop Configured Configrable Configuration Tool 源码详解
  8. 『Python动手学』PyQt5入门教程
  9. html5swf小游戏源码,亲测可用120个H5小游戏实例源码
  10. 数据库可视化工具(SQLyog安装教程)
  11. FAT32文件系统结构
  12. 无线通信设备安装工程概预算编制_起重设备安装资质承接多大工程
  13. 计算机怎么连接网络打印,无线局域网怎么连接网络打印机呢?
  14. CTex:字体字号设置
  15. 题目58 工厂流水线调度(ok)
  16. 如何求置换奇偶性、对换乘积
  17. html打开方式怎么没有反应,为什么我点开启程序没反应
  18. 嵌入式硬件开发工程师涉及哪些工作内容?
  19. 【app测试】adb常用指令及华为卸载预置软件
  20. MySQL(十三):分区表( Partitioning Table)

热门文章

  1. 通过git上传代码到代码库步骤(亲测有效)
  2. 『ML笔记』深入浅出字典学习2(Dictionary Learning)
  3. Windows动态链接库
  4. 毕业找到工作后很久未更新博客了(后续不定时更新)
  5. JavaScript模块化入门
  6. android 4.2 开机动画,android开机动画制作与播放原理简介 (适用android4-4.2,其他版本未试验)...
  7. 销售人说话“十大忌”
  8. iOS开发系列课程(08) --- 事件处理详解和手势操作
  9. Android12 AndroidManifest使用uses-library编译报错解决
  10. error: *EXECUTABLE* uses VFP register arguments