將羅馬數字樣式應用於計數器輸出

CSS

body {
  counter-reset: item-counter;
}

.item {
  counter-increment: item-counter;
}

.item:before {
  content: counter(item-counter, upper-roman) ". "; /* by specifying the upper-roman as style the output would be in roman numbers */
}

HTML

<div class='item'>Item No: 1</div>
<div class='item'>Item No: 2</div>
<div class='item'>Item No: 3</div>

在上面的例子中,計數器的輸出將顯示為 I,II,III(羅馬數字),而不是通常的 1,2,3,因為開發人員明確指定了計數器的樣式。