成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

HTML5中div section article的區別

開發 前端
本文主要分析了HTML5中div 、section 、article的區別,一起來看,希望對你有幫助。

剛剛開始接觸 HTML5 時,對它的標簽很不適應,甚至一度有點反感。尤其是對 divsectionarticle 這幾個標簽,實在弄不清楚應該使用在什么場合下。

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 就是適用的。

 

  1. <article> 
  2. <hgroup> 
  3. <h1>Apples</h1> 
  4. <h2>Tasty, delicious fruit!</h2> 
  5. </hgroup> 
  6. <p>The apple is the pomaceous fruit of the apple tree.</p> 
  7. <section> 
  8. <h1>Red Delicious</h1> 
  9. <p>These bright red apples are the most common found in many  
  10. supermarkets.</p> 
  11. </section> 
  12. <section> 
  13. <h1>Granny Smith</h1> 
  14. <p>These juicy, green apples make a great filling for  
  15. apple pies.</p> 
  16. </section> 
  17. </article> 

 

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 中是不是完整的。看這段內容脫離了所在的語境,是否還是完整的、獨立的。

例子:

 

  1. <article> 
  2. <header> 
  3. <h1>The Very First Rule of Life</h1> 
  4. <p><time pubdate datetime="2009-10-09T14:28-08:00"></time></p> 
  5. </header> 
  6. <p>If there's a microphone anywhere near you, assume it's hot and  
  7. sending whatever you're saying to the world. Seriously.</p> 
  8. <p>...</p> 
  9. <footer> 
  10. <a href="?comments=1">Show comments...</a> 
  11. </footer> 
  12. </article><article> 
  13. <header> 
  14. <h1>The Very First Rule of Life</h1> 
  15. <p><time pubdate datetime="2009-10-09T14:28-08:00"></time></p> 
  16. </header> 
  17. <p>If there's a microphone anywhere near you, assume it's hot and  
  18. sending whatever you're saying to the world. Seriously.</p> 
  19. <p>...</p> 
  20. <section> 
  21. <h1>Comments</h1> 
  22. <article> 
  23. <footer> 
  24. <p>Posted by: George Washington</p> 
  25. <p><time pubdate datetime="2009-10-10T19:10-08:00"></time></p> 
  26. </footer> 
  27. <p>Yeah! Especially when talking about your lobbyist friends!</p> 
  28. </article> 
  29. <article> 
  30. <footer> 
  31. <p>Posted by: George Hammond</p> 
  32. <p><time pubdate datetime="2009-10-10T19:15-08:00"></time></p> 
  33. </footer> 
  34. <p>Hey, you have the same first name as me.</p> 
  35. </article> 
  36. </section> 
  37. </article> 

總結

div section article ,語義是從無到有,逐漸增強的。div 無任何語義,僅僅用作樣式化或者腳本化的鉤子(hook),對于一段主題性的內容,則就適用 section,而假如這段內容可以脫離上下文,作為完整的獨立存在的一段內容,則就適用 article。原則上來說,能使用 article 的時候,也是可以使用 section 的,但是實際上,假如使用 article 更合適,那么就不要使用 section 。nav 和 aside 的使用也是如此,這兩個標簽也是特殊的 section,在使用 nav 和 aside 更合適的情況下,也不要使用 section 了。

對于 div 和 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.” 一旦遇到沖突,最終用戶優先,其次是作者,其次是實現者,其次標準制定者,***才是理論上的完滿。

【編輯推薦】

  1. 超酷的HTML5網站設計
  2. HTML5書籍推薦
  3. Jeremy Keith談HTML5設計原則
  4. 學習HTML5不可錯過的12家國外網站
責任編輯:于鐵 來源: 糖伴西紅柿
相關推薦

2010-08-17 09:41:22

DIVSpan

2013-01-24 10:26:04

HTML5HTML 5HTML5的未來

2015-06-19 15:39:49

國外HTML5酷站欣賞

2011-05-13 17:36:05

HTML

2023-03-16 09:00:00

HTML5HTML語言

2012-07-31 09:53:33

HTML5進度條

2012-06-05 10:48:23

2013-10-21 15:24:49

html5游戲

2011-05-13 17:41:40

2011-01-14 17:53:33

HTML5cssweb

2015-04-30 11:26:38

HTML5與APP的抉

2012-08-31 17:09:31

FacebookHTML5W3C

2016-05-13 17:14:51

華為HTML5

2017-01-03 18:09:33

HTML5本地存儲Web

2011-05-12 15:42:16

HTML5

2012-05-03 14:54:15

HTML5

2012-08-30 16:24:04

HTML5歐朋W3C

2011-05-11 12:59:18

HTML5

2012-08-27 10:00:06

HTML5

2012-06-25 14:57:27

HTML5
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩欧美在线免费观看视频 | 欧美黄a | 日韩欧美在线视频一区 | 久久精品国产一区二区三区 | 成人小视频在线 | 亚洲欧美激情精品一区二区 | 成人国产在线视频 | 精品一区二区三区电影 | 爱爱视频在线观看 | 国产一区二区三区欧美 | 欧美五月婷婷 | 欧美在线一区二区三区 | 久久综合一区二区 | 午夜一级做a爰片久久毛片 精品综合 | 日韩精品一区二区三区在线播放 | 日韩精品 电影一区 亚洲 | 亚洲第一天堂 | 91高清视频在线观看 | 欧美国产日本一区 | 欧美精品在线一区二区三区 | 在线国产视频 | 国产精品伦一区二区三级视频 | 国产精品乱码一区二区三区 | 国产午夜三级一区二区三 | 玖玖综合网 | 国产精品美女久久久久久免费 | 一区二区三区欧美在线观看 | 一区二区三区四区不卡 | 瑞克和莫蒂第五季在线观看 | 久久一视频 | 青娱乐av | 午夜av电影 | www.中文字幕.com | 国产成人99久久亚洲综合精品 | 亚洲国产一区二区三区在线观看 | 天天干亚洲 | 亚州视频在线 | 中文一区| 精品国产一区二区三区四区在线 | 亚洲高清久久 | 国产在线永久免费 |