<ul>: 無序列表元素
<ul> HTML 元素表示一個無序專案列表,通常呈現為帶專案符號的列表。
嘗試一下
屬性
此元素包含 全域性屬性。
compact已棄用-
此布林屬性暗示列表應以緊湊樣式呈現。此屬性的解釋取決於 使用者代理,並且並非在所有瀏覽器中都有效。
警告: 不要使用此屬性,因為它已棄用:請改用 CSS。要實現與
compact屬性類似的效果,可以使用line-heightCSS 屬性,其值為80%。 type已棄用-
此屬性設定列表的專案符號樣式。在 HTML3.2 和 HTML 4.0/4.01 過渡版本中定義的值為
circlediscsquare
在 WebTV 介面中定義了第四種專案符號型別,但並非所有瀏覽器都支援它:
triangle。如果不存在,並且沒有 CSS
list-style-type屬性應用於元素,則使用者代理會根據列表的巢狀級別選擇專案符號型別。警告: 不要使用此屬性,因為它已棄用;請改用 CSS
list-style-type屬性。
使用說明
<ul>元素用於對沒有數字順序的一組專案進行分組,它們在列表中的順序無關緊要。通常,無序列表專案以專案符號顯示,專案符號可以有多種形式,例如點、圓圈或正方形。專案符號樣式不在頁面的 HTML 描述中定義,而是在其關聯的 CSS 中定義,使用list-style-type屬性。<ul>和<ol>元素可以根據需要進行巢狀。此外,巢狀列表可以在<ol>和<ul>之間交替使用,沒有限制。<ol>和<ul>元素都代表一個專案列表。它們的區別在於,對於<ol>元素,順序是有意義的。要確定使用哪一個,嘗試更改列表項的順序;如果含義發生改變,則應使用<ol>元素,否則可以使用<ul>。
示例
簡單示例
html
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
</ul>
結果
巢狀列表
html
<ul>
<li>first item</li>
<li>
second item
<!-- Look, the closing </li> tag is not placed here! -->
<ul>
<li>second item first subitem</li>
<li>
second item second subitem
<!-- Same for the second nested unordered list! -->
<ul>
<li>second item second subitem first sub-subitem</li>
<li>second item second subitem second sub-subitem</li>
<li>second item second subitem third sub-subitem</li>
</ul>
</li>
<!-- Closing </li> tag for the li that
contains the third unordered list -->
<li>second item third subitem</li>
</ul>
<!-- Here is the closing </li> tag -->
</li>
<li>third item</li>
</ul>
結果
無序列表中的有序列表
html
<ul>
<li>first item</li>
<li>
second item
<!-- Look, the closing </li> tag is not placed here! -->
<ol>
<li>second item first subitem</li>
<li>second item second subitem</li>
<li>second item third subitem</li>
</ol>
<!-- Here is the closing </li> tag -->
</li>
<li>third item</li>
</ul>
結果
技術摘要
規範
| 規範 |
|---|
| HTML 標準 # the-ul-element |
瀏覽器相容性
BCD 表格僅在瀏覽器中載入
另請參閱
- 其他與列表相關的 HTML 元素:
<ol>、<li>、<menu> - 可能對
<ul>元素進行樣式設定特別有用的 CSS 屬性list-style屬性,用於選擇序數顯示的方式。- CSS 計數器,用於處理複雜的巢狀列表。
line-height屬性,用於模擬已棄用的compact屬性。margin屬性,用於控制列表縮排。