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?

isherwood
  • 58,414
  • 16
  • 114
  • 157
Bikas Lin
  • 689
  • 5
  • 16

1 Answers1

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>
isherwood
  • 58,414
  • 16
  • 114
  • 157