ol.striped li:nth-child(odd) { background: #fefefe; }
ol.striped li:nth-child(even) { background: #efefef; }
零 JS、零表達式、全瀏覽器支援 (IE9+),維護最簡單。
.test ol li {
/* IE5.5-8 專用,效能差、已棄用 */
background-color: expression(this.sourceIndex % 2 ? '#efefef' : '#fefefe');
}
不建議使用:Expression 每次重繪都執行,嚴重拖慢頁面,IE8 已移除支援。
<div class="test">
<ol>
<li>觀自在菩薩</li>
<li>行深般若波羅密多時</li>
<li>照見五蘊皆空</li>
<!-- 更多項目 -->
</ol>
</div>
使用 `
ol.custom-counter {
list-style: none;
counter-reset: item;
}
ol.custom-counter li::before {
counter-increment: item;
content: counter(item) '. ';
color: #666; font-weight: bold;
margin-right: 8px;
}
完全脫離預設編號樣式,支援任意格式(如 01、A、①)。