萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

HTML 標籤分類學大全:塊級、行內、可變元素、HTML5 內容模型與 CSS display 對應關係完整圖譜

HTML5 內容模型:告別簡單二分法

HTML4 僅分「塊級」與「行內」。HTML5 引入 **7 大內容類別**,元素可同時屬於多類,更精確描述嵌套規則:

類別核心元素直觀理解
Metadata content`` 子元素:`title` `meta` `link` `style` `script` `base` `noscript` `template`文檔元數據,不渲染可視內容
Flow content幾乎所有 body 內元素:`div` `p` `h1-h6` `ul` `table` `form` `section` `article` `aside` `header` `footer` `address` `hr` `pre` `blockquote` `figure` `video` `audio` `canvas` `iframe`...「流式內容」—— 文檔主體骨架
Sectioning content`article` `section` `nav` `aside`創建大綱節點,影響文檔大綱算法
Heading content`h1-h6` `hgroup`標題,定義節點標題
Phrasing content`a` `em` `strong` `span` `img` `input` `select` `textarea` `label` `button` `code` `time` `data` `abbr` `ruby` `br` `wbr`...「措辭內容」—— 段落內文本級標記
Embedded content`img` `video` `audio` `canvas` `iframe` `embed` `object` `picture` `svg` `math`引入外部資源或非 HTML 命名空間
Interactive content`a` `button` `details` `embed` `iframe` `label` `select` `textarea` `input` (type≠hidden) `audio[controls]` `video[controls]`用戶可交互元素,**不可嵌套** (a 不能包 a、button 不能包 button)

傳統二分法映射 (兼容舊認知)

傳統分類HTML5 對應類別典型元素CSS display 默認值
塊級元素Flow content (大部分)`div` `p` `h1-h6` `ul` `ol` `table` `form` `section` `header` `footer``block` / `list-item` / `table`
行內元素Phrasing content (大部分)`span` `a` `strong` `em` `img` `input` `button` `label` `code` `br``inline` / `inline-block` / `inline-table`
可變元素視上下文屬 Flow 或 Phrasing`del` `ins` `map` `object` `audio` `video` `iframe` `noscript`視上下文

嵌套規則鐵律

  1. Flow content 可包含 Flow / Phrasing / Embedded / Interactive (視具體元素)。
  2. Phrasing content 僅可包含 Phrasing content** (嚴禁包含 `div`、`p`、`table` 等 Flow 元素)。
  3. Interactive content 不可嵌套 Interactive content** (`
  4. 特定父元素強制子元素類別**:
    • `
        `/`
          ` 只能直接包含 `
        1. `、`
copyright © 萬盛學電腦網 all rights reserved