編者按:原本打算自己寫一篇同主題的文章,剛好在部落格群看到這篇整理得不錯的內容,於是轉載過來與大家分享,希望對日常開發有所幫助。
li { list-style-image: url(images/disc.gif); }
這行樣式讓清單的項目符號改成指定的圖片。若想改用其他形式,可以透過 list-style-type 指定。
CSS1 時期即支援:
CSS2 新增:
li { list-style-image: url(images/disc.gif); }
以 disc.gif 取代預設的項目符號,適合需要品牌化視覺的清單。
li { list-style-position: outside; } /* 或 inside */
水平線 hr 也是常需要調整預設外觀的元素。相關的樣式屬性包括:
hr {
border-bottom-style: dotted;
border-left-style: dotted;
border-right-style: dotted;
border-top-style: dotted;
height: 1;
width: 100%;
align: left;
color: #86BCD4;
}
其中 Shade: no; 是 IE 特有的寫法,用來關閉 hr 預設的立體陰影。
想要一條乾淨的虛線,最簡潔的寫法是:
hr {
border: 1px dashed #86BCD4;
height: 1;
}
實務上有兩個提醒:一是 hr 在不同瀏覽器的預設邊距差異不小,通常要補上 margin 才能對齊;二是若只是為了視覺分隔,用區塊元素的 border-top 往往比 hr 更好控制,語意上也更貼切。