我们可以检索li的默认计数器值吗?

问题描述:

我们可以在 CSS 中检索li的默认计数器值吗?


例如:

如果我有6 < li> ,分隔在2 < ol> ,但我想要< li> 从1到6,而不是1到3两次。我在第二个的< li> 上使用 value =4 ; ol> ,所以它工作,但现在,因为我使用

Can we retrieve in CSS the default counter value of an li?

For example:
If I have 6 <li>, separated in 2 <ol>, but I want the <li> to be listed from 1 to 6, not 1 to 3 twice. I used value="4" on the first <li> of the second <ol>, so it worked, but now since I'm using

ol {
  counter-reset: i 0;
}

ol li:before {
    content: counter(i);    
    counter-increment: i;
    font-weight: bold;
}​

content:counter(i); 上的 / code>不会计入 value =4第二个< ol>

我可以做些什么吗?

查看 JsFiddle

这是否适合你的需要? 在JSFiddle上查看

Does this suit your needs? View on JSFiddle

<ol>
  <li>test</li>
  <li>test</li>
  <li>test</li>
</ol>
<ol>
  <li>test</li>
  <li>test</li>
  <li>test</li>
</ol>



CSS



CSS

ol:first-of-type {
  counter-reset: i 0;
}

ol li:before {
  content: counter(i);    
  counter-increment: i;
  font-weight: bold;
}​