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

首頁 > 開發 > HTML5 > 正文

詳解HTML5中div和section以及article的區別

2024-09-05 07:21:12
字體:
來源:轉載
供稿:網友

剛剛開始接觸 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 就是適用的。

XML/HTML Code復制內容到剪貼板
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拉萨市| 襄城县| 鄱阳县| 灵川县| 永善县| 富民县| 利川市| 安徽省| 陇西县| 革吉县| 宜兰市| 建平县| 内江市| 正阳县| 铅山县| 任丘市| 绥化市| 永川市| 祁东县| 仙游县| 乳源| 四川省| 扬中市| 孟村| 北京市| 常熟市| 汝南县| 富顺县| 河北省| 泰州市| 朝阳县| 深泽县| 黄陵县| 青海省| 阜宁县| 汉沽区| 鸡东县| 即墨市| 吉木乃县| 竹溪县| 肥东县|