在html5中,<a>元素的子元素能夠是塊級元素,這在之前是被認爲不符合規則的。本文將詳細介紹html5的標籤嵌套規則html
html5出現以前,常常把元素按照block、inline、inline-block來區分。在html5中,元素再也不按照display屬性來區分,而是按照內容模型來區分,分爲元數據型(metadata content)、區塊型(sectioning content)、標題型(heading content)、文檔流型(flow content)、語句型(phrasing content)、內嵌型(embedded content)、交互型(interactive content)。元素不屬於任何一個類別,被稱爲穿透的;元素可能屬於不止一個類別,稱爲混合的。html5
元數據元素(metadata content)是能夠被用於說明其餘內容的表現或行爲,或者在當前文檔和其餘文檔之間創建聯繫的元素canvas
base link meta noscript script style template title
流元素(flow content)是在應用程序和文檔的主體部分中使用的大部分元素ruby
a abbr address area(若是它是map元素的子元素) article aside audio b bdi bdo blockquote br button canvas cite code data datalist del dfn div dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header hr i iframe img input ins kbd keygen label main map mark math meter nav noscript object ol output p pre progress q ruby s samp script section select small span strong sub sup svg table template textarea time u ul var video wbr text
區塊型元素(sectioning content)是用於定義標題及頁腳範圍的元素app
article aside nav section
標題型元素(heading content)定義一個區塊/章節的標題ide
h1 h2 h3 h4 h5 h6
語句型元素(phrasing content)是用於標記段落級文本的元素svg
a abbr area (若是它是map元素的子級) audio b bdi bdo br button canvas cite code data datalist del dfn em embed i iframe img input ins kbd keygen label map mark math meter noscript object output progress q ruby s samp script select small span strong sub sup svg template textarea time u var video wbr text
嵌入型元素(embedded content)是引用或插入到文檔中其餘資源的元素spa
audio canvas embed iframe img math object svg video
交互型元素(interactive content)是專門用於與用戶交互的元素code
a audio(若是設置了controls屬性) button embed iframe img(若是設置了usemap屬性) input(若是type屬性不爲hidden) keygen label object(若是設置了usemap屬性) select textarea video (若是設置了controls屬性)
【1】子元素是流元素orm
<article>、<section>、<blockquote>、<li>、<dd>、<figcaption>、<div>、<main>、<td>
【1.1】子元素是流元素,不包括<main>元素
<aside>、<nav>
【1.2】子元素是流元素,但不包括<table>元素
<caption>
【1.3】子元素是流元素,但不包括<form>元素
<form>
【1.4】子元素是流元素,但不包括<header>、<footer>、<main>元素
<header>、<footer>、<main>
【1.5】子元素是流元素,但不包括<header>、<footer>、區塊型元素(sectioning content)、標題型元素(heading content)
<dt>、<th>
【1.6】子元素是流元素,但不包括<header>、<footer>、<address>、區塊型元素(sectioning content)、標題型元素(heading content)
<address>
【1.7】子元素是一個<figcaption>元素,緊跟着流元素
<figure>
【1.8】子元素是一個<legend>元素,緊跟着流元素
<filedset>
【2】子元素是語句型元素
<h1>、<h2>、<h3>、<h4>、<h5>、<h6>、<p>、<pre>、<em>、<strong>、<small>、<s>、<cite>、<q>、<abbr>、<data>、<time>、<code>、<var>、<samp>、<kbd>、<sub>、<sup>、<i>、<b>、<u>、<mark>、<bdi>、<bdo>、<span>、<input>、<output>、<legend>、<label>
【2.1】子元素是語句型元素,但不包括和自身相同的元素
<dfn>、<progress>、<meter>
【2.2】子元素是語句型元素,但不包括交互型元素(interactive content)
<button>
【3】子元素是transparent(以它的父元素容許的子元素爲準)
<ins>、<del>、<map>
【3.1】子元素是transparent(以它的父元素容許的子元素爲準),但不包括交互型元素(interactive content)
<a>
【3.2】子元素能夠沒有、能夠是<param>元素,也能夠是transparent(以它的父元素容許的子元素爲準)
<object>
【4】無子元素
<hr>、<br>、<wbr>、<img>、<embed>、<param>、<source>、<track>、<area>、<col>、<keygen>
【4.1】子元素能夠沒有、能夠是<li>元素,也能夠是<script>、<template>元素
<ol>、<ul>
【4.2】子元素能夠沒有、能夠是<dt>和<dd>元素,也能夠是<script>、<template>元素
<dl>
【4.3】子元素能夠沒有,能夠是<option>、<optgroup>,也能夠是<script>、<template>元素
<select>
【4.4】子元素能夠沒有,能夠是<option>,也能夠是<script>、<template>元素
<optgroup>
【4.5】子元素能夠沒有、能夠是<option>元素
<datalist>
【4.6】子元素能夠沒有、也能夠是<track>元素,也能夠是<source>元素
<audio>、<video>
【4.7】子元素能夠沒有,也能夠是<col>、<template>元素
<colgroup>
【4.8】子元素能夠沒有,能夠是<tr>,也能夠是<script>、<template>元素
<tbody>、<thead>、<tfoot>
【4.9】子元素能夠沒有,能夠是<tr>、<th>,也能夠是<script>、<template>元素
<tr>
【5】子元素是<caption>、<colgroup>、<thead>、<tfoot>、<tbody>,也能夠是<script>、<template>元素
<table>
【6】子元素是文本內容
<textarea>
【6.1】子元素能夠沒有,也能夠是文本內容
<option>
關於每一個元素的詳細嵌套規則,上部分已經詳細介紹。這部分主要對經常使用標籤的嵌套規則進行總結
【1】<h1>、<h2>、<h3>、<h4>、<h5>、<h6>、<p>的子元素是區塊型元素(sectioning content)、標題型元素(heading content