如果使用psuedo元素,如何以特定数字启动有序列表?

时间:2016-10-03 23:17:45

标签: css

你好我有一个由三个有序列表组成的页面,它们之间有内容,所以有必要将它们分成三个不同的列表。我想控制第二个和第三个有序列表的起始编号。我在我的有序列表中使用了伪造的:before,因此我可以自定义数字。

这是我的CSS:

.postid-1028 ol {
    counter-reset: item;
    list-style: none;
}

.postid-1028 ol li {
    padding-left: 55px;
}

.postid-1028 ol li:before {
    content: counter(item) ". ";
    counter-increment: item;
    left: 20px;
}

是否可以使用某些css或jquery以我自己选择的数字开始第二个列表,例如7而不是1?

谢谢!

1 个答案:

答案 0 :(得分:3)

您可以在ol元素中定义一个数字增量。

counter-reset函数有一个可选的整数值(默认为0),可用于从该数字开始计数:

counter-reset: [ <identifier> <integer>? ]

CODE SNIPPET:

&#13;
&#13;
ol {
  list-style: none;
  counter-reset: my-counter 6;
}
li {
  counter-increment: my-counter;
}
li::before {
  content: counter(my-counter);
}
&#13;
<ol>
  <li></li>
  <li></li>
  <li></li>
</ol>
&#13;
&#13;
&#13;