CSS 将罗马数字样式应用于计数器输出

示例

的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,因为开发人员已明确指定了计数器的样式。