?
This document uses PHP Chinese website manual Release
HTML<dl>
元素 (或HTML描述列表元素)是一個包含術語定義以及描述的列表,通常用于展示詞匯表或者元數(shù)據(jù) (鍵-值對列表)。
內容類別 | 流內容,如果<dl>元素的子元素包含一個名稱值組,則可觸及的內容。 |
---|---|
允許的內容 | 零個或多個組,每個組由一個或多個<dt>元素,后跟一個或多個<dd>元素組成,可選地與<script>和<template>元素混合在一起?;颍ㄔ赪HATWG HTML中):一個或多個<div>元素,可選地與<script>和<template>元素混合在一起。 |
標記遺漏 | 沒有,起始和結束標簽都是強制性的。 |
允許的父母 | 任何接受流內容的元素。 |
允許ARIA角色 | 組,演示文稿 |
DOM界面 | HTMLDListElement |
該元素包含全局屬性。
單條語句與描述
<dl> <dt>Firefox</dt> <dd> A free, open source, cross-platform, graphical web browser developed by the Mozilla Corporation and hundreds of volunteers. </dd> <!-- Other terms and descriptions --></dl>
輸出
<dl> <dt>Firefox</dt> <dt>Mozilla Firefox</dt> <dt>Fx</dt> <dd> A free, open source, cross-platform, graphical web browser developed by the Mozilla Corporation and hundreds of volunteers. </dd> <!-- Other terms and descriptions --></dl>
輸出:
<dl> <dt>Firefox</dt> <dd> A free, open source, cross-platform, graphical web browser developed by the Mozilla Corporation and hundreds of volunteers. </dd> <dd> The Red Panda also known as the Lesser Panda, Wah, Bear Cat or Firefox, is a mostly herbivorous mammal, slightly larger than a domestic cat (60 cm long). </dd> <!-- Other terms and descriptions --></dl>
輸出:
同樣的,該元素同樣可以支持在一個列表中出現(xiàn)多條語句以及多條描述。
描述列表可以很方便的將元數(shù)據(jù)展示為鍵-值對列表:
<dl> <dt>Name</dt> <dd>Godzilla</dd> <dt>Born</dt> <dd>1952</dd> <dt>Birthplace</dt> <dd>Japan</dd> <dt>Color</dt> <dd>Green</dd></dl>
小技巧:通過 CSS3 ,我們可以很容易的在術語后面添加一個與內容無關的分隔符號,比如:
dt::after { content: ": ";}
<div>
元素中包裝名稱值組WHATWG HTML允許在 <div> 元素中的 <dl> 元素中包裝每個名稱 - 值組。當使用元數(shù)據(jù)時,或全局屬性適用于整個組或用于樣式時,這可能很有用。
<dl> <div> <dt>Name</dt> <dd>Godzilla</dd> </div> <div> <dt>Born</dt> <dd>1952</dd> </div> <div> <dt>Birthplace</dt> <dd>Japan</dd> </div> <div> <dt>Color</dt> <dd>Green</dd> </div></dl>
請不要將該元素(也不要用 <ul> 元素)用來在頁面創(chuàng)建具有縮進效果的內容。雖然這樣的結果樣式看上去沒問題,但是,這是很糟糕的做法,并且語義也不清晰。
要改變描述列表中描述的縮進量,請使用 CSSmargin 屬性。
規(guī)范 | 狀態(tài) | 評論 |
---|---|---|
HTML生活標準該規(guī)范中'<dl>'的定義。 | 生活水平 | |
HTML5該規(guī)范中'<dl>'的定義。 | 建議 | |
HTML 4.01規(guī)范該規(guī)范中'<dl>'的定義。 | 建議 | 初始定義 |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |