HTML5 - section、article和div

简介: HTML5 - section、article和div

【1】section

section是带有语义的标签。


W3C中定义:

<section> 标签定义文档中的节(section、区段)。比如章节、页眉、页脚或文档中的其他部分。

<section>
  <h1>PRC</h1>
  <p>The People's Republic of China was born in 1949...</p>
</section>



HTML标准是这样写的:


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.


Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis.

A Web site’s home page could be split into sections for an introduction, news items, and contact information.


Note: Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element.


Note: The section element is not a generic container element.

When an element is needed only for styling purposes or as a convenience for scripting, authors are encouraged to use the div element instead.


A general rule is that the section element is appropriate only if the element’s contents would be listed explicitly in the document’s outline.


翻译如下:


section元素表示文档或应用的一个部分。所谓“部分”,这里是指按照主题分组的内容区域,通常会带有标题。


section元素使用的例子如章节回目,选项卡式对话框中的各种选项卡页或者论文以数字编号的小节。网站的主页可能分成介绍、最新内容、联系信息等不同section。


注意:在将元素的内容组合在一起时,鼓励作者使用“article”元素,而不是“section”元素。


注意:section 元素不是通用的容器元素。如果仅仅是用于设置样式或脚本处理,应用div元素。一条简单的准则是,只有元素内容会被列在文档大纲中时,才适合用section元素。



翻译section:



也就是说一个section通常由内容和标题组成,通常不推荐那些没有标题的内容用section。

另外,以报纸为例,分为好多版块。每个版块就是一个 section,包括标题和内容。

故,section侧重点在”部分”,”版块”和”节”的概念上。


【2】article

W3C:


<article>标签定义外部的内容。

<article>标签定义独立的内容。

<article>标签定义的内容本身必须是有意义的且必须是独立于文档的其余部分。


外部内容可以是来自一个外部的新闻提供者的一篇新的文章,或者来自 blog 的文本,或者是来自论坛的文本,亦或是来自其他外部源内容。

<article>
<a href="http://www.apple.com">Safari 5 released</a><br />
7 Jun 2010. Just after the announcement of the new iPhone 4 at WWDC, 
Apple announced the release of Safari 5 for Windows and Mac......
</article>

问答:


article 是一个特殊的 section 标签,它比 section 具有更明确的语义, 它代表一个独立的、完整的相关内容块。一般来说, article 会有标题部分(通常包含在 header 内),有时也会 包含 footer 。虽然 section 也是带有主题性的一块内容,但是无论从结构上还是内容上来说,article 本身就是独立的、完整的。


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.


This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.


When article elements are nested, the inner article elements represent articles that are in principle related to the contents of the outer article.


For instance, a blog entry on a site that accepts user-submitted comments could represent the comments as article elements nested within the article element for the blog entry.


Author information associated with an article element (q.v. the address element) does not apply to nested article elements.


When the main content of the page (i.e. excluding footers, headers, navigation blocks, and sidebars) is all one single self-contained composition, that content may be marked with an article, but it is technically redundant in that case (since it’s self-evident that the page is a single composition, as it is a single document).

This example shows a blog post using the article element, with some schema.org annotations:
<article itemscope itemtype="http://schema.org/BlogPosting">
 <header>
  <h1 itemprop="headline">The Very First Rule of Life</h1>
  <p><time itemprop="datePublished" datetime="2009-10-09">3 days ago</time></p>
  <link itemprop="url" href="?comments=0">
 </header>
 <p>If there's a microphone anywhere near you, assume it's hot and
 sending whatever you're saying to the world. Seriously.</p>
 <p>...</p>
 <footer>
  <a itemprop="discussionUrl" href="?comments=1">Show comments...</a>
 </footer>
</article>
Here is that same blog post, but showing some of the comments:
<article itemscope itemtype="http://schema.org/BlogPosting">
 <header>
  <h1 itemprop="headline">The Very First Rule of Life</h1>
  <p><time itemprop="datePublished" datetime="2009-10-09">3 days ago</time></p>
  <link itemprop="url" href="?comments=0">
 </header>
 <p>If there's a microphone anywhere near you, assume it's hot and
 sending whatever you're saying to the world. Seriously.</p>
 <p>...</p>
 <section>
  <h1>Comments</h1>
  <article itemprop="comment" itemscope itemtype="http://schema.org/UserComments" id="c1">
   <link itemprop="url" href="#c1">
   <footer>
    <p>Posted by: <span itemprop="creator" itemscope itemtype="http://schema.org/Person">
     <span itemprop="name">George Washington</span>
    </span></p>
    <p><time itemprop="commentTime" datetime="2009-10-10">15 minutes ago</time></p>
   </footer>
   <p>Yeah! Especially when talking about your lobbyist friends!</p>
  </article>
  <article itemprop="comment" itemscope itemtype="http://schema.org/UserComments" id="c2">
   <link itemprop="url" href="#c2">
   <footer>
    <p>Posted by: <span itemprop="creator" itemscope itemtype="http://schema.org/Person">
     <span itemprop="name">George Hammond</span>
    </span></p>
    <p><time itemprop="commentTime" datetime="2009-10-10">5 minutes ago</time></p>
   </footer>
   <p>Hey, you have the same first name as me.</p>
  </article>
 </section>
</article>
Notice the use of footer to give the information for each comment (such as who wrote it and when): the footer element can appear at the start of its section when appropriate, such as in this case. (Using header in this case wouldn't be wrong either; it's mostly a matter of authoring preference.)

更多信息参考原始地址:article-element

也就是说,article是独立的,有时引用外部文章,可以在诸多”零件”部分使用(如用户评论)等。与section相比,它更倾向于一个独立性,完整性。


【3】div

DIV是层叠样式表中的定位技术,全称DIVision,即为划分。有时可以称其为图层。DIV在编程中又叫做整除,即只得商的整数。 DIV元素是用来为HTML(标准通用标记语言下的一个应用)文档内大块(block-level)的内容提供结构和背景的元素。


W3C:

定义和用法


<div>可定义文档中的分区或节(division/section)。

<div> 标签可以把文档分割为独立的、不同的部分。它可以用作严格的组织工具,并且不使用任何格式与其关联。

<div> 是一个块级元素。这意味着它的内容自动地开始一个新行。实际上,换行是 <div> 固有的唯一格式表现。可以通过<div> 的 class 或 id 应用额外的样式。


注释:<div> 是一个块级元素,也就是说,浏览器通常会在 div 元素前后放置一个换行符。

提示:请使用 <div> 元素来组合块级元素,这样就可以使用样式对它们进行格式化。

<body>
 <h1>NEWS WEBSITE</h1>
  <p>some text. some text. some text...</p>
  ...
 <div class="news">
  <h2>News headline 1</h2>
  <p>some text. some text. some text...</p>
  ...
 </div>
 <div class="news">
  <h2>News headline 2</h2>
  <p>some text. some text. some text...</p>
  ...
 </div>
 ...
</body>

div,块级元素,无语义标签,通用容器,便于样式修饰。

目录
相关文章
|
2月前
html中div内容居中的方法使用弹性盒子居中
html中div内容居中的方法使用弹性盒子居中
19 0
|
2天前
|
前端开发 开发者 SEO
HTML基础标签解析:H1-H6、DIV与P的正确使用方法
HTML基础标签解析:H1-H6、DIV与P的正确使用方法
8 0
|
28天前
|
前端开发 容器
HTML <div> 和<span>
【6月更文挑战第2天】HTML <div> 和<span>。
19 5
|
2月前
|
前端开发 容器
HTML <div> 和<span>
HTML <div> 和<span>
|
10月前
|
Serverless
html 页面中动态计算 div 元素的宽度
html 页面中动态计算 div 元素的宽度
111 2
|
12月前
|
前端开发 Android开发
HTML网页制作 Div+CSS
HTML网页制作 Div+CSS
80 0
|
前端开发 容器
HTML的层(div)和块(span)
大多数 HTML元素被定义为块级元素或内联元素。“块级元素”译为 block level element,“内联元素”译为 inline element。那什么是块级元素,什么又是内联元素呢?它们分别是用来做什么的呢?
HTML的层(div)和块(span)
|
前端开发 容器
零基础html5+div+css+js网页开发教程第009期 导航栏css美化
零基础html5+div+css+js网页开发教程第009期 导航栏css美化
159 0
|
JavaScript 容器
零基础html5+div+css+js网页开发教程第010期 图片轮播案例
零基础html5+div+css+js网页开发教程第010期 图片轮播案例
102 0
|
前端开发 程序员
零基础html5+div+css+js网页开发教程第007期 网页基本代码框架
零基础html5+div+css+js网页开发教程第007期 网页基本代码框架
139 0