div、section、article 的区别

作者:糖伴西红柿 来源:前端观察 时间:2011-02-26 15:39:00 

HTML5 中 div section article 的区别

刚刚开始接触 HTML5 时,对它的标签很不适应,甚至一度有点反感。尤其是对 div、section、article 这几个标签,实在弄不清楚应该使用在什么场合下。

div

HTML Spec: “The div element has no special meaning at all.”

这个标签是我们见得最多、用得最多的一个标签。本身没有任何语义,用作布局以及样式化或脚本的钩子(hook)。

section

HTML Spec: “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.”

与 div 的无语义相对,简单地说 section 就是带有语义的 div 了,但是千万不要觉得真得这么简单。section 表示一段专题性的内容,一般会带有标题。看到这里,我们也许会想到,那么一篇博客文章,或者一条单独的评论岂不是正好可以用 section 吗?接着看:

“Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the elemen.”

当元素内容聚合起来更加言之有物时,应该使用 article 来替换 section 。

那么,section 应该什么时候用呢?再接着看:

“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.”

section 应用的典型场景有文章的章节、标签对话框中的标签页、或者论文中有编号的部分。一个网站的主页可以分成简介、新闻和联系信息等几部分。其实我对这里传达信息很感兴趣,因为感觉 section 和下面要介绍的 artilce 更加适用于模块化应用,这个话题以后会出篇专门的文章来讨论,这里暂时略过。

要注意,W3C 还警告说:

“The section element is not a generic container element. When an element is needed 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 不仅仅是一个普通的容器标签。当一个标签只是为了样式化或者方便脚本使用时,应该使用 div 。一般来说,当元素内容明确地出现在文档大纲中时,section 就是适用的。


<article>
 <hgroup>
  <h1>Apples</h1>
  <h2>Tasty, delicious fruit!</h2>
 </hgroup>
 <p>The apple is the pomaceous fruit of the apple tree.</p>
 <section>
  <h1>Red Delicious</h1>
  <p>These bright red apples are the most common found in many
  supermarkets.</p>
 </section>
 <section>
  <h1>Granny Smith</h1>
  <p>These juicy, green apples make a great filling for
  apple pies.</p>
 </section>
</article>

标签:div,html5,section,article
0
投稿

猜你喜欢

  • 软件与网站设计的区别

    2009-05-04 14:30:00
  • 如何把图片也存到数据库中去?

    2009-11-06 13:56:00
  • 背景图片千万不要gzip压缩,尤其是PNG

    2009-06-19 12:42:00
  • ASP的数据命名有什么规则吗?

    2009-10-28 18:23:00
  • ASP获取网页内容(解决乱码问题)

    2009-07-26 10:44:00
  • CSS制作圆角导航的另一思路

    2008-11-06 11:39:00
  • ASP程序中输出Excel文件实例一则

    2008-11-07 15:29:00
  • 浅析“Rich”设计模式

    2009-03-12 12:36:00
  • 探讨关于404错误页面设置的问题

    2011-12-01 10:59:38
  • asp 简单分页代码

    2011-03-11 10:53:00
  • ASP设计常见问题及解答精要

    2009-04-21 11:16:00
  • DWCS3-CSS布局之一CSS规则大纲

    2008-06-11 18:48:00
  • 使用一条INSERT语句完成多表插入

    2010-03-18 11:08:00
  • 2008农历新年各大网站Logo秀

    2008-02-11 16:33:00
  • 如何用ASP发送HTML格式的邮件?

    2010-06-11 19:41:00
  • 深刻理解Oracle数据库的启动和关闭

    2010-07-26 13:08:00
  • 从品牌网站看交互设计

    2009-08-18 12:39:00
  • 设计评论表单[译]

    2009-03-25 20:41:00
  • 在JScript中使用ADODB.Stream判断文件编码

    2008-06-08 13:03:00
  • 安装MySQL的步骤和方法

    2009-07-30 08:38:00
  • asp之家 网络编程 m.aspxhome.com