是否有一种纯粹的 CSS 方法可以在 2 个单独的有序列表中继续对有序列表进行编号?

Is there a pure CSS way to continue ordered list numbering across 2 seperated ordered list?

演示:https://jsfiddle.net/jacobgoh101/uqrkaodc/3/

<ol>
  <li>a</li>
</ol>
<ul>
  <li>b</li>
</ul>
<ol>
  <li>c</li>
  <li>d</li>
  <li>e</li>
</ol>
ol li {
  counter-increment: list-0;
  list-style: none;
}

ol li:before {
  content: counter(list-0, decimal) '. ';
}

当前结果

1 a
• b
1 c
2 d
3 e

有没有办法实现下面这个结果?

预期结果

1 a
• b
2 c
3 d
4 e

(上下文:尝试使嵌套列表与 QuillJS 一起工作。https://github.com/quilljs/quill/issues/979

更新:

由于 QuillJS 库的限制,我真的无法将 start="2" 添加到 ol 或更改 HTML 结构。

我想我需要一个纯粹的 CSS 解决方案,如果可能的话。

似乎使用 <ol start="2'> 会起作用

https://www.w3schools.com/tags/att_ol_start.asp

也就是说,不确定为什么不能将无序列表嵌套在原始有序列表中

<ol>
  <li>a</li>
  <ul>
    <li>b</li>
  </ul>
  <li>c</li>
  <li>d</li>
  <li>e</li>
</ol>

ol {
  list-style-type: none;
  /* Remove default numbering */
}

ol > li:before {
  counter-increment: mycounter;
  content: counter(mycounter) ". ";
}

ol:first-of-type {
  counter-reset: mycounter;
}
<ol>
  <li>a</li>
</ol>
<ul>
  <li>b</li>
</ul>
<ol>
  <li>c</li>
  <li>d</li>
  <li>e</li>
</ol>

如果您可以将这些 OL/UL 包装到一个共同的父元素中,那么您可以重置该父元素的计数器,并仅针对 ol li 增加它:

div {
  counter-reset: list-0;
}

ol li {
  counter-increment: list-0;
  list-style: none;
}

ol li:before {
  content: counter(list-0, decimal) '. ';
}
<div>
  <ol>
    <li>a</li>
  </ol>
  <ul>
    <li>b</li>
  </ul>
  <ol>
    <li>c</li>
    <li>d</li>
    <li>e</li>
  </ol>
</div>

对于更多新浏览器,您可以设置自定义开始计数器抛出 CSS 计数器集。这是集成了 UL 列表和自定义嵌套列表开头的嵌套计数器示例。

https://jsfiddle.net/atorn/fqb8oz6g/

...
ol {
  counter-reset: l;
  &> li {
    counter-increment: l;
    display: -ms-grid;
    display: flow-root;
    position: relative;
  }
  &>li::before { // counters with numbered lists
    content: counters(l, '.') ')';
    position: absolute;
    z-index: 104;
    top: 0;
    left: -0.625em;
    width: 1.7em;
...
    background-color: #e0e5e6;
  }
  ol >li::before { // more wide field for Level 3 indexes
    z-index: 103;
    width: 2.2em;
    margin-left: -0.7em;
    padding-left: 0.4em;
  }
}
.o0>ol {counter-set: l -1}
.o1>ol {counter-set: l 0}
.o2>ol {counter-set: l 1}
.o3>ol {counter-set: l 2}
.o4>ol {counter-set: l 3}
.o5>ol {counter-set: l 4}
.o6>ol {counter-set: l 5}
...

https://caniuse.com/?search=counter-set - CSS 属性: counter-set show browser supports (Safari 14.x is not supports custom beginning of counters).

截图在ChromeOrdered lists with CSS property counter-set