section和div的区别

来源:互联网 发布:淘宝店铺新店推广 编辑:程序博客网 时间:2024/05/18 22:45

在做移动web的时候,参考的案例用的是section而不是div,就好奇,section是什么鬼?section是属于听说过但是一直都没有用过的一个元素,所以百度查了一下section和div的区别,收获如下:

作者:贺师俊
链接:http://www.zhihu.com/question/20227599/answer/14582155
来源:知乎
著作权归作者所有,转载请联系作者获得授权。

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的例子包括书的章节回目、多tab对话框的每个tab页、论文以数字编号的小节。网站的主页可能分成介绍、最新内容、联系信息等section。

注意:网页作者应使用article而不是section元素,如果其内容是用于聚合(syndicate)。【比如blog首页上的每篇blog。又如论坛帖子的一楼、二楼、三楼……n楼。通常这样的每部分内容形式上是类似的,但是来源是独立的。】

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

至于何时使用,基本上可以这两点:
section 不是一个专用来做容器的标签,专用的是 div
section 里应该有 标题(h1~6),但文章中推荐用 article 来代替
我们可以理解为一个非文章段落,有明确 id 的一个特殊模块容器(不是专用以包住块的容器)。

也就是说,一般情况下作为元素容器,使用div而不是section,那么section就没有用了吗?图样图森破。
这种情况下使用section就比div要好
section,顾名思义就是一个章节,比如:

<section><h1>WWF</h1><p>The World Wide Fund for Nature (WWF) is....</p></section>

至于为什么要用,是为了语义化,有section、article、dl看这多舒服,人也好理解,计算机也好理解,比满眼的div好多了。

1 0
原创粉丝点击