0
I. Introduction
  1. Introduction 1
  2. Introduction 2
II. Services
  3. Services 1
  4. Services 2

As you can see in the above example, the number of the second ol is started after the last number of the first ol.

Of course, I found the attribute start but I want to implement it without using that attribute. Because using the start attribute is not dynamic. If I add one element to the ol, I should modify all start attributes after that.

How can I do this?

1
  • Please see How to Ask, then provide some markup in a demo snippet using the editor.
    – isherwood
    Nov 7, 2022 at 14:28

1 Answer 1

0

We can use a CSS counter to accomplish this, along with some positioning.

.parent-list {
  counter-reset: child-count;
}

.parent-list ol li {
  list-style-type: none;
  position: relative;
  counter-increment: child-count;
}

.parent-list ol li::before {
  content: counter(child-count)'.';
  position: absolute; 
  left: -1rem;
}
<ol class="parent-list">
  <li>Parent One
    <ol>
      <li>Child One</li>
      <li>Child Two</li>
    </ol>
  </li>

  <li>Parent Two
    <ol>
      <li>Child One</li>
      <li>Child Two</li>
    </ol>
  </li>
</ol>

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.