在 CSS 中,ul 與 li 是構建列表的核心標籤。透過 list-style-type 屬性,我們可以輕鬆移除預設項目符號,或替換為自定義圖片。
ul li {
list-style-type: none;
}
ul li {
list-style-type: none;
list-style-image: url(/blog/images/icon.gif);
}
ul {
list-style-type: none;
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
}
ul li {
background: #CCC;
}
利用 display: block 使連結佔滿整個列表項目區塊,配合 :hover 偽類實現背景變色。
ul {
list-style-type: none;
margin: 0;
}
ul li a {
display: block;
width: 100%;
background: #ccc;
}
ul li a:hover {
background: #999;
}
關鍵提示: display: block; 必須加入,才能讓連結以區塊形式顯示,覆蓋整個可點擊區域。
透過 float: left 讓列表項目並排顯示,常用於導航選單製作。
ul {
list-style-type: none;
width: 100%;
}
ul li {
width: 80px;
float: left;
}
type 可設定符號樣式:disc(實心圓)、circle(空心圓)、square(方塊)。ul 或 ol 中。type 僅適用於無序清單,效果同 ul。value 僅適用於有序清單 ol,指定起始編號。以數字、字母或羅馬數字編號,同樣使用 li 作為子項目。
總結:ul 定義列表容器與符號風格,li 定義具體項目內容,兩者結合才能構建完整語意清單。