国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > HTML5 > 正文

HTML5中div、article、section的區(qū)別及使用介紹

2024-09-05 07:20:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
最近正在學(xué)習(xí)html5,剛接觸html5,感覺有點(diǎn)不適應(yīng),因?yàn)橛幸恍?biāo)簽改變了,特別是div, section article這三個(gè)標(biāo)簽,查了一些資料,也試著用html5和css3布局網(wǎng)頁(yè),稍微有點(diǎn)頭緒了,下邊還有一個(gè)我剛剛布局好的一個(gè)簡(jiǎn)單的網(wǎng)頁(yè),供大家參考,先看一下,最起碼心里對(duì)html5的結(jié)構(gòu)有些概念。

div

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

這個(gè)標(biāo)簽是我們見得最多、用得最多的一個(gè)標(biāo)簽。本身沒有任何語(yǔ)義,用作布局以及樣式化或腳本的鉤子(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 的無(wú)語(yǔ)義相對(duì),簡(jiǎn)單地說(shuō) section 就是帶有語(yǔ)義的 div 了,但是千萬(wàn)不要覺得真得這么簡(jiǎn)單。section 表示一段專題性的內(nèi)容,一般會(huì)帶有標(biāo)題。看到這里,我們也許會(huì)想到,那么一篇博客文章,或者一條單獨(dú)的評(píng)論豈不是正好可以用 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.”

當(dāng)元素內(nèi)容聚合起來(lái)更加言之有物時(shí),應(yīng)該使用 article 來(lái)替換 section 。

那么,section 應(yīng)該什么時(shí)候用呢?再接著看:

“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 應(yīng)用的典型場(chǎng)景有文章的章節(jié)、標(biāo)簽對(duì)話框中的標(biāo)簽頁(yè)、或者論文中有編號(hào)的部分。一個(gè)網(wǎng)站的主頁(yè)可以分成簡(jiǎn)介、新聞和聯(lián)系信息等幾部分。其實(shí)我對(duì)這里傳達(dá)信息很感興趣,因?yàn)楦杏X section 和下面要介紹的 artilce 更加適用于模塊化應(yīng)用,這個(gè)話題以后會(huì)出篇專門的文章來(lái)討論,這里暫時(shí)略過(guò)。

要注意,W3C 還警告說(shuō):

“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 不僅僅是一個(gè)普通的容器標(biāo)簽。當(dāng)一個(gè)標(biāo)簽只是為了樣式化或者方便腳本使用時(shí),應(yīng)該使用 div 。一般來(lái)說(shuō),當(dāng)元素內(nèi)容明確地出現(xiàn)在文檔大綱中時(shí),section 就是適用的。

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 是一個(gè)特殊的 section 標(biāo)簽,它比 section 具有更明確的語(yǔ)義, 它代表一個(gè)獨(dú)立的、完整的相關(guān)內(nèi)容塊。一般來(lái)說(shuō), article 會(huì)有標(biāo)題部分(通常包含在 header 內(nèi)),有時(shí)也會(huì) 包含 footer 。雖然 section 也是帶有主題性的一塊內(nèi)容,但是無(wú)論從結(jié)構(gòu)上還是內(nèi)容上來(lái)說(shuō),article 本身就是獨(dú)立的、完整的。

HTML Spec 中接著又列舉了一些 article 適用的場(chǎng)景。 “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.”

當(dāng) article 內(nèi)嵌 article 時(shí),原則上來(lái)說(shuō),內(nèi)部的 article 的內(nèi)容是和外層的 article 內(nèi)容是相關(guān)的。例如,一篇博客文章中,包含用戶提交的評(píng)論的 article 就應(yīng)該潛逃在包含博客文章 article 之中。

問(wèn)題是怎么才算“完整的獨(dú)立內(nèi)容”?有個(gè)最簡(jiǎn)單的判斷方法是看這段內(nèi)容在 RSS feed 中是不是完整的。看這段內(nèi)容脫離了所在的語(yǔ)境,是否還是完整的、獨(dú)立的。

例子:

html頁(yè)面:

復(fù)制代碼
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 岫岩| 五常市| 米脂县| 民丰县| 肥西县| 永州市| 长乐市| 广西| 牙克石市| 荆门市| 余庆县| 昭觉县| 炉霍县| 和平县| 巨野县| 阳泉市| 天津市| 明溪县| 南京市| 教育| 会昌县| 黄骅市| 滨州市| 昌江| 西盟| 金坛市| 北宁市| 逊克县| 丰城市| 赣州市| 上林县| 城口县| 田东县| 灵宝市| 太湖县| 凤凰县| 八宿县| 收藏| 恭城| 石阡县| 卫辉市|