<dl> (Description List) 是**語義最精確**的「鍵值對/術語-定義」結構,比 `
<dl><dt> (Description Term)<dd> (Description Details)<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
<dd>用於描述文件呈現樣式</dd>
<dt>JavaScript</dt>
<dt>JS</dt>
<dd>ECMAScript 實作,瀏覽器腳本語言</dd>
</dl>
dl.specs { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; }
dl.specs dt { font-weight: 600; color: #333; }
dl.specs dd { margin: 0; color: #666; }
✅ 現代最佳:Grid 自動對齊、響應式極簡。
🔄 兼容舊瀏覽器:`display: table` / `float` + `clear`。
dl.float dt { float: left; width: 120px; clear: left; font-weight: bold; }
dl.float dd { margin-left: 140px; padding: 4px 0; }
dl.float::after { content: ''; display: table; clear: both; }
⚠️ 需固定 `dt` 寬度,內容過長會換行錯位。
dl.flex { display: flex; flex-wrap: wrap; gap: 8px 16px; }
dl.flex dt { flex: 0 0 120px; font-weight: 600; }
dl.flex dd { flex: 1 1 calc(100% - 136px); margin: 0; min-width: 150px; }
✅ 寬度不足時自動換行,適合響應式。
<dl class="product-specs">
<div><dt>品牌</dt><dd>Acme Corp.</dd></div>
<div><dt>型號</dt><dd>X-2000</dd></div>
<div><dt>螢幕</dt><dd>6.7" AMOLED, 120Hz</dd></div>
<div><dt>處理器</dt><dd>Snapdragon 8 Gen 3</dd></div>
<div><dt>記憶體</dt><dd>12GB LPDDR5X</dd></div>
<div><dt>儲存</dt><dd>256GB / 512GB / 1TB UFS 4.0</dd></div>
<div><dt>電池</dt><dd>5000mAh, 120W 快充</dd></div>
<div><dt>作業系統</dt><dd>Android 14 (HyperOS 1.0)</dd></div>
</dl>
<style>
.product-specs { display: grid; grid-template-columns: 100px 1fr; gap: 10px 20px; max-width: 600px; margin: 20px auto; font-size: 0.95rem; line-height: 1.6; }
.product-specs dt { font-weight: 600; color: #1a1a2e; }
.product-specs dd { margin: 0; color: #4a4a68; }
.product-specs div { display: contents; } /* 讓 div 透明化,dt/dd 直接參與 grid */
@media (max-width: 480px) {
.product-specs { grid-template-columns: 80px 1fr; font-size: 0.9rem; }
}
</style>
<dl class="faq">
<div>
<dt><details><summary>如何退貨?</summary></details></dt>
<dd>收到商品 7 天內可申請退貨,請保持原包裝完整...</dd>
</div>
<div>
<dt><details><summary>運費如何計算?</summary></details></dt>
<dd>單筆訂單滿 $1000 免運,否則收取 $80...</dd>
</div>
</dl>
<style>
.faq dt summary { cursor: pointer; font-weight: 600; list-style: none; }
.faq dt summary::-webkit-details-marker { display: none; }
.faq dt summary::before { content: '+ '; transition: transform .2s; display: inline-block; }
.faq dt[open] summary::before { transform: rotate(45deg); }
.faq dd { margin: 8px 0 0 0; padding: 12px; background: #f8f9fa; border-radius: 4px; }
</style>
<dl itemscope itemtype="https://schema.org/Product">
<dt itemprop="name">產品名稱</dt>
<dd itemprop="description">產品描述...</dd>
<dt>價格</dt>
<dd><span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span itemprop="price" content="2999">$2,999</span>
<meta itemprop="priceCurrency" content="TWD">
</span></dd>
</dl>
| 場景 | 推薦標籤 | 理由 |
|---|---|---|
| 鍵值對、屬性列表、規格表 | <dl> | 語義精確,螢幕閱讀器朗讀「術語:定義」 |
| 多欄位表格數據(可排序、對齊) | <table> | 表格語義、原生排序/篩選支援 |
| 單純項目清單 | <ul>/<ol> | 列表語義,無鍵值關係 |
善用 `