百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>html5教程> HTML5中div和section以及article的区别剖析-
分享文章到:

HTML5中div和section以及article的区别剖析-

发布时间:09/01 来源:未知 浏览: 关键词:
这篇文章主要介绍了详解HTML5中div和section以及article的区别,引自W3C的注明而且加以代码实例列举,需要的伴侣可以参照 下 这篇文章主要介绍了详解HTML5中p和section以及article的区别,引自W3C的注明而且加以代码实例列举,需要的伴侣可以参照 下

刚刚开端接触 HTML5 时,对它的标签很不顺应,甚至一度有点恶感。尤为是对 div、section、article 这几个标签,实在弄不分明应当运用在什么场所下。
div

HTML Spec:

The p 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 p 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 不仅仅是一个普通的容器标签。当一个标签只是为了样式化或者利便足本运用时,应当运用 p 。个别来说,当元素内容明白地涌现在文档大纲中时,section 就是适用的。

    

Apples

Tasty, delicious fruit!

The apple is the pomaceous fruit of the apple tree.

Red Delicious

These bright red apples are the most common found in many supermarkets.

Granny Smith

These juicy, green apples make a great filling for apple pies.

article

HTML Spec:

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

article 是一个特别的 section 标签,它比 section 拥有更明白的语义, 它代表一个独立的、完备的相干内容块。个别来说, article 会有标题局部(平常包括在 header 内),有时也会 包括 footer 。虽然 section 也是带有主题性的一块内容,但是不管从构造上还是内容上来说,article 自身就是独立的、完备的。

HTML Spec 中接着又列举了一些 article 适用的场景。

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.

当 article 内嵌 article 时,准则上来说,内部的 article 的内容是和外层的 article 内容是相干的。例如,一篇博客文章中,包括会员提交的评价的 article 就应当潜逃在包括博客文章 article 之中。

题目是怎么才算“完备的独立内容”?有个最简略的推断办法是看这段内容在 RSS feed 中是不是完备的。看这段内容离开了所在的语境,可否还是完备的、独立的。

例子:


    

The Very First Rule of Life

If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.

...

Show comments...

The Very First Rule of Life

If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.

...

Comments

Posted by: George Washington

Yeah! Especially when talking about your lobbyist friends!

Posted by: George Hammond

Hey, you have the same first name as me.

总结

p section article ,语义是从无到有,逐步加强的。p 无任何语义,仅仅用作样式化或者足本化的钩子(hook),关于一段主题性的内容,则就适用 section,而假设这段内容可以离开高低文,作为完备的独立存在的一段内容,则就适用 article。准则上来说,能运用 article 的时候,也是可以运用 section 的,但是现实上,假设运用 article 更合适,那么就不要运用 section 。nav 和 aside 的运用也是如此,这两个标签也是特别的 section,在运用 nav 和 aside 更合适的状况下,也不要运用 section 了。

关于 p 和 section、 article 以及其他标签的区分比拼简略。关于 section 和 article 的区分乍看比拼难,其实重点就是看看这段内容离开了整体是不是还能作为一个完备的、独立的内容而存在,这里面的重点又在完备身上。由于其实提及来 section 包括的内容也能算作独立的一块,但是它只能算是组成整体的一局部,article 才是一个完备的整体。

由于其实有些时候每个人都有本人的看法,所以未免有难于决断的时候,怎么办?

在 HTML5 设计道理 中,有一条是专门用来解决相似状况的:

终究会员优先(Priority of Constituencies)

“In case of conflict, consider users over authors over implementors over specifiers over theoretical purity.” 一旦碰到冲突,终究会员优先,其次是作者,其次是实现者,其次规范拟定者,最后才是理论上的美满。

举荐各位多读几遍 HTML5 设计道理,这才是纷繁天下背后的终究奥义。

以上就是本文的全部内容,但愿对大家的学习有所帮忙,更多相干内容请关注百分百源码网!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板