HTML 的列表分兩種:有序列表(ol)預設用阿拉伯數字標示,無序列表(ul)則用小圓點。透過 CSS 的 list-style-type 屬性,這兩種標識都可以換成其他樣式。
無序列表可用的值有:disc(實心圓點)、circle(空心圓圈)、square(方形)。有序列表可用的值有:upper-roman(大寫羅馬數字)、lower-roman(小寫羅馬數字)、upper-alpha(大寫英文字母)、lower-alpha(小寫英文字母),以及 decimal(十進位數字)。
舉例來說,若希望有序列表的編號顯示為大寫羅馬數字,可以這樣寫:
LI.upperroman { list-style-type: upper-roman; }
若要一次定義多種標識樣式,方便在頁面中隨時套用,可以集中寫在樣式區塊裡:
<style>
LI.upperroman { list-style-type: upper-roman; }
LI.lowerroman { list-style-type: lower-roman; }
LI.upperalpha { list-style-type: upper-alpha; }
LI.loweralpha { list-style-type: lower-alpha; }
LI.disc { list-style-type: disc; }
LI.circle { list-style-type: circle; }
LI.decimal { list-style-type: decimal; }
LI.square { list-style-type: square; }
</style>
寫法是在 ol 或 li 上套用對應的 class,例如 <ol class="upperalpha">。
如果希望完全拿掉標識,用 list-style-type: none;想自訂圖示,則可用 list-style-image: url(...) 指定一張小圖。另外,list-style-position 可控制標識落在內容框內(inside)或外(outside),多行文字時差異明顯。
現代專案中,很多人會直接 list-style: none 歸零,再用 ::before 偽元素搭配 content 畫出自訂項目符號,彈性遠高於原生標識,也更方便對齊與控制間距。