Настроить нумерацию вложенных упорядоченных списков - PullRequest
0 голосов
/ 21 сентября 2018

У меня есть вложенные списки, структуру которых я не могу изменить.Первый элемент li не должен быть включен в нумерацию, однако его дочерние элементы должны ВСЕМ быть пронумерованы.Вот JsFiddle .

ol li ol {
  counter-reset: section;
  list-style-type: none;
}

ol li ol li::before {
  counter-increment: section;
  content: counters(section, ".") " ";
}
<ol id="root">
  <li>List item two with subitems (this should not be numbered):
    <ol id="toc0">
      <li>Subitem 1 (This should be numbered 1)</li>
      <li>Subitem 2 (This should be 2)</li>
      <ol>
        <li> subitem (this should be 2.1)</li>
        <li> subitem (this should be 2.2)</li>
        <ol>
          <li> subitem (This should be 2.2.1)</li>
          <li> subitem (This should be 2.2.2)</li>
        </ol>
      </ol>
      <li>Subitem 3 (This should be 3)</li>
      <li>Subitem 4 (This should be 4)</li>
    </ol>
  </li>
</ol>

1 Ответ

0 голосов
/ 21 сентября 2018

У вас неверная разметка, ol не может быть прямым потомком другого ol.Вы должны обновить HTML, чтобы исправить это, ваш существующий CSS отлично работает с небольшим редактированием.

ol {
  list-style: none;
}

ol li ol {
  counter-reset: section;
}

ol li ol li::before {
  counter-increment: section;
  content: counters(section, ".") " ";
}
<ol id="root">
  <li>List item two with subitems (this should not be numbered):
    <ol id="toc0">
      <li>Subitem 1 (This should be numbered 1)</li>
      <li>
        Subitem 2 (This should be 2)
        <ol>
          <li>subitem (this should be 2.1)</li>
          <li>
            subitem (this should be 2.2)
            <ol>
              <li> subitem (This should be 2.2.1)</li>
              <li> subitem (This should be 2.2.2)</li>
            </ol>
          </li>
        </ol>
      </li>
      <li>Subitem 3 (This should be 3)</li>
      <li>Subitem 4 (This should be 4)</li>
    </ol>
  </li>
</ol>
...