內容是否有順序/序數關係?
├─ 是 → <ol> (有序列表)
└─ 否 → 是否為「術語-定義」鍵值對?
├─ 是 → <dl> (定義列表)
└─ 否 → <ul> (無序列表)
項目順序不影響含義的集合。導航菜單、標籤雲、功能清單、購物車商品、文章標籤。
<ul>
<li>蘋果</li>
<li>香蕉</li>
<li>橙子
<ul> <!-- 嵌套子列表 -->
<li>血橙</li>
<li>臍橙</li>
</ul>
</li>
</ul>
ul { list-style-type: disc; } /* 實心圓 ● 默認 */
ul { list-style-type: circle; } /* 空心圓 ○ */
ul { list-style-type: square; } /* 實心方 ■ */
ul { list-style-type: none; } /* 移除標記,配合 ::before 自定義 */
ul { list-style-image: url(bullet.svg); } /* 自定義圖片標記 */
ul { list-style-position: inside; } /* 標記在內容框內(影響對齊) */
/* 現代自定義標記最佳實踐 */
ul.custom-bullets {
list-style: none;
padding-left: 1.5em;
}
ul.custom-bullets > li::before {
content: "→";
display: inline-block;
width: 1.5em;
margin-left: -1.5em;
color: #1E90FF;
}
項目順序影響含義的序列。步驟教程、排名榜、法律條文、書籍章節、麵包屑導航。
<ol start="5"> <!-- 從 5 開始編號 -->
<ol reversed> <!-- 逆序編號 -->
<ol type="A"> <!-- A, B, C... -->
<ol type="a"> <-- a, b, c... -->
<ol type="I"> <-- I, II, III... (羅馬數字大寫) -->
<ol type="i"> <-- i, ii, iii... (羅馬數字小寫) -->
<li value="10"> <!-- 強制指定某項編號,後續遞增 -->
.steps {
counter-reset: step-counter;
list-style: none;
padding-left: 2rem;
}
.steps li {
counter-increment: step-counter;
position: relative;
padding-left: 1.5rem;
}
.steps li::before {
content: "Step " counter(step-counter) ".";
position: absolute;
left: 0;
font-weight: bold;
color: #1E90FF;
}
/* 嵌套計數器 */
ol { counter-reset: section; }
li::before { content: counters(section, ".") " "; counter-increment: section; }
鍵值對關係:術語-定義、屬性-值、問題-答案、元數據展示、對話記錄、鍵值配置。
<!-- 一對一 -->
<dl>
<dt>HTML</dt>
<dd>超文本標記語言</dd>
</dl>
<!-- 一對多:一個術語多個定義 -->
<dl>
<dt>瀏覽器引擎</dt>
<dd>Blink (Chrome, Edge)</dd>
<dd>Gecko (Firefox)</dd>
<dd>WebKit (Safari)</dd>
</dl>
<!-- 多對一:多個術語共享定義 -->
<dl>
<dt>HTML</dt>
<dt>HyperText Markup Language</dt>
<dd>構建網頁的標準標記語言</dd>
</dl>
<!-- 組合 -->
<dl>
<dt>Name</dt> <dd>張三</dd>
<dt>Email</dt> <dd>zhang@example.com</dd>
<dt>Roles</dt>
<dd>Admin</dd>
<dd>Editor</dd>
</dl>
/* 模式 1:經典 dt/dd 塊級堆疊 */
dl { margin: 0; }
dt { font-weight: bold; margin-top: 1em; }
dd { margin: 0; margin-left: 1.5rem; }
/* 模式 2:水平並排(表格狀) */
dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.5em 1.5em; }
dt { font-weight: bold; }
dd { margin: 0; }
/* 模式 3:Flex 換行並排 */
dl { display: flex; flex-wrap: wrap; gap: 0.5em 2em; }
dt { flex: 0 0 120px; font-weight: bold; }
dd { flex: 1; margin: 0; min-width: 150px; }
三大列表各司其職:`