您好!欢迎访问家园网-www.jy.wang!

家园网

讲解html5中可以省略结束标记的元素

网络 作者:本站 点击:

可以省略结束标记的元素

  • li(list - item)‌:词源为列表项。用法是在有序列表(ol)或无序列表(ul)中用于定义单个列表项。例如:

<ul>
  <li>苹果</li>
  <li>香蕉</li>
</ul>

省略结束标记情况:当后面跟随li元素,或者它是父元素的最后一个子元素时,</li>可以省略。如:

<ul>
  <li>苹果
  <li>香蕉
</ul>
  • dt(definition term)‌:词源为定义术语。用法是在定义列表(dl)中用于定义术语。例如:

<dl>
  <dt>猫</dt>
  <dd>一种宠物</dd>
</dl>

省略结束标记情况:当后面跟随dt或dd元素时,</dt>可以省略。如:

<dl>
  <dt>猫
  <dd>一种宠物
</dl>
  • dd(definition description)‌:词源为定义描述。用法是在定义列表(dl)中用于定义术语对应的描述。例如:

<dl>
  <dt>狗</dt>
  <dd>人类的好朋友</dd>
</dl>

省略结束标记情况:当后面跟随dd或dt元素,或者它是父元素的最后一个子元素时,</dd>可以省略。如:

<dl>
  <dt>狗
  <dd>人类的好朋友
</dl>
  • p(paragraph)‌:词源为段落。用法是用于定义一个段落。例如:

<p>这是一个段落内容。</p>

省略结束标记情况:当后面跟随address、article、aside等特定元素时,</p>可以省略。如:

<p>这是一个段落内容。
<article>这是一篇文章。</article>
  • option‌:词源为选项。用法是在select元素中定义下拉菜单的选项。例如:

<select>
  <option value="1">选项1</option>
  <option value="2">选项2</option>
</select>

省略结束标记情况:在select元素中,</option>通常可省略。如:

<select>
  <option value="1">选项1
  <option value="2">选项2
</select>
  • thead(table head)‌:词源为表格头部。用法是在table元素中定义表格的表头部分。例如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
  </tbody>
</table>

省略结束标记情况:在table元素中,</thead>可省略。如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
  </tbody>
</table>
  • tbody(table body)‌:词源为表格主体。用法是在table元素中定义表格的主体内容部分。例如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
  </tbody>
</table>

省略结束标记情况:在table元素中,</tbody>可省略。如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
</table>
  • tr(table row)‌:词源为表格行。用法是在table的tbody、thead或tfoot中定义表格的一行。例如:

<table>
  <tbody>
    <tr>
      <td>数据1</td>
      <td>数据2</td>
    </tr>
  </tbody>
</table>

省略结束标记情况:在tbody、thead或tfoot中,</tr>可省略。如:

<table>
  <tbody>
    <tr>
      <td>数据1</td>
      <td>数据2</td>
  </tbody>
</table>
  • td(table data)‌:词源为表格数据。用法是在tr元素中定义表格单元格(普通单元格)。例如:

<table>
  <tr>
    <td>单元格内容1</td>
    <td>单元格内容2</td>
  </tr>
</table>

省略结束标记情况:在tr元素中,</td>可省略。如:

<table>
  <tr>
    <td>单元格内容1
    <td>单元格内容2
  </tr>
</table>
  • th(table header cell)‌:词源为表格表头单元格。用法是在tr元素中定义表格表头单元格。例如:

<table>
  <tr>
    <th>表头内容1</th>
    <th>表头内容2</th>
  </tr>
</table>

省略结束标记情况:在tr元素中,</th>可省略。如:

<table>
  <tr>
    <th>表头内容1
    <th>表头内容2
  </tr>
</table>
  • rt(ruby text)‌:词源为注音文本(在东亚语言中用于为汉字添加注音等)。用法是在ruby元素中用于定义注音或注释文本。例如:

<ruby>
  漢<rt>hàn</rt>
</ruby>

省略结束标记情况:在ruby元素中,</rt>可省略。如:

<ruby>
  漢<rt>hàn
</ruby>
  • rp(ruby parenthesis)‌:词源为注音括号(在东亚语言ruby注释中用于在不支持ruby的浏览器显示括号)。用法是在ruby元素中用于在不支持ruby的浏览器中显示括号。例如:

<ruby>
  好<rp>(</rp><rt>hǎo</rt><rp>)</rp>
</ruby>

省略结束标记情况:在ruby元素中,</rp>可省略。如:

<ruby>
  好<rp>(</rp><rt>hǎo</rt><rp>
</ruby>
  • optgroup(option group)‌:词源为选项组。用法是在select元素中用于对option进行分组。例如:

<select>
  <optgroup label="水果">
    <option value="apple">苹果</option>
    <option value="banana">香蕉</option>
  </optgroup>
</select>

省略结束标记情况:在select元素中,</optgroup>可省略。如:

<select>
  <optgroup label="水果">
    <option value="apple">苹果
    <option value="banana">香蕉
</select>
  • colgroup‌:词源为列组。用法是在table元素中用于对表格的列进行分组。例如:

<table>
  <colgroup>
    <col span="2" style="background - color:lightblue;">
  </colgroup>
  <tr>
    <th>姓名</th>
    <th>年龄</th>
  </tr>
  <tr>
    <td>张三</td>
    <td>20</td>
  </tr>
</table>

省略结束标记情况:在table元素中,</colgroup>可省略。如:

<table>
  <colgroup>
    <col span="2" style="background - color:lightblue;">
  <tr>
    <th>姓名</th>
    <th>年龄</th>
  </tr>
  <tr>
    <td>张三</td>
    <td>20</td>
  </tr>
</table>
  • tfoot(table foot)‌:词源为表格脚注。用法是在table元素中定义表格的脚注部分。例如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="2">合计</td>
    </tr>
  </tfoot>
</table>

省略结束标记情况:在table元素中,</tfoot>可省略。如:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>20</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="2">合计</td>
</table>

列表总结

类别词源及含义用法举例注意事项
lilist - item,列表项在有序列表(ol)或无序列表(ul)中定义单个列表项<ul><li>苹果</li><li>香蕉</li></ul>当后面跟随li元素,或者它是父元素的最后一个子元素时,</li>可以省略
dtdefinition term,定义术语在定义列表(dl)中定义术语<dl><dt>猫</dt><dd>一种宠物</dd></dl>当后面跟随dt或dd元素时,</dt>可以省略
dddefinition description,定义描述在定义列表(dl)中定义术语对应的描述<dl><dt>狗</dt><dd>人类的好朋友</dd></dl>当后面跟随dd或dt元素,或者它是父元素的最后一个子元素时,</dd>可以省略
pparagraph,段落定义一个段落<p>这是一个段落内容。</p>当后面跟随address、article、aside等特定元素时,</p>可以省略
option选项在select元素中定义下拉菜单的选项<select><option value="1">选项1</option><option value="2">选项2</option></select>在select元素中,</option>通常可省略
theadtable head,表格头部在table元素中定义表格的表头部分<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody><tr><td>张三</td><td>20</td></tr></tbody></table>在table元素中,</thead>可省略
tbodytable body,表格主体在table元素中定义表格的主体内容部分<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody><tr><td>张三</td><td>20</td></tr></tbody></table>在table元素中,</tbody>可省略
trtable row,表格行在table的tbody、thead或tfoot中定义表格的一行<table><tbody><tr><td>数据1</td><td>数据2</td></tr></tbody></table>在tbody、thead或tfoot中,</tr>可省略
tdtable data,表格数据在tr元素中定义表格单元格(普通单元格)<table><tr><td>单元格内容1</td><td>单元格内容2</td></tr></table>在tr元素中,</td>可省略
thtable header cell,表格表头单元格在tr元素中定义表格表头单元格<table><tr><th>表头内容1</th><th>表头内容2</th></tr></table>在tr元素中,</th>可省略
rtruby text,注音文本(在东亚语言中用于为汉字添加注音等)在ruby元素中定义注音或注释文本<ruby>漢<rt>hàn</rt></ruby>在ruby元素中,</rt>可省略
rpruby parenthesis,注音括号(在东亚语言ruby注释中用于在不支持ruby的浏览器显示括号)在ruby元素中在不支持ruby的浏览器中显示括号<ruby>好<rp>(</rp><rt>hǎo</rt><rp>)</rp></ruby>在ruby元素中,</rp>可省略
optgroupoption group,选项组在select元素中对option进行分组<select><optgroup label="水果"><option value="apple">苹果</option><option value="banana">香蕉</option></optgroup></select>在select元素中,</optgroup>可省略
colgroup列组在table元素中对表格的列进行分组<table><colgroup><col span="2" style="background - color:lightblue;"></colgroup><tr><th>姓名</th><th>年龄</th></tr><tr><td>张三</td><td>20</td></tr></table>在table元素中,</colgroup>可省略
tfoottable foot,表格脚注在table元素中定义表格的脚注部分<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody><tr><td>张三</td><td>20</td></tr></tbody><tfoot><tr><td colspan="2">合计</td></tr></tfoot></table>在table元素中,</tfoot>可省略


标签: