HTML/CSS 多级嵌套列表编号

标签 html css html-lists nested-lists

<分区>

有没有办法使用直接的 HTML 和 CSS 列表(<ul><ol>)实现以下编号?

1. Link 1
2. Link 2
3. Link 3
    3.1. Link 3.1
    3.2. Link 3.2
    3.3. Link 3.3
4. Link 4
    4.1. Link 4.1
        4.1.1 Link 4.1.1
        4.1.2 Link 4.1.2
5. Link 5

提前致谢!

最佳答案

你可以使用 CSS counters :

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

li:before {
    counter-increment: section;
    content: counters(section, ".") ". Link " counters(section, ".") " ";
}

工作演示(also on JSBin):

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

li:before {
  counter-increment: section;
  content: counters(section, ".") ". Link " counters(section, ".") " ";
}
<ol>
  <li></li>
  <li></li>
  <li>
    <ol>
      <li></li>
      <li></li>
      <li></li>
    </ol>
  </li>
  <li>
    <ol>
      <li>    
        <ol>
        <li></li>
        <li></li>
        </ol>
      </li>
    </ol>
  </li>
  <li></li>
</ol>

关于HTML/CSS 多级嵌套列表编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909732/

相关文章:

css - Less Framework > CSS 是否先加载所有内容然后选择?

css - 鼠标离开后如何在CSS中恢复颜色?

php - 如何在 HTML 5 中制作视频 session 应用程序?

HTML, CSS - 使文本框宽度相同

HTML/CSS - 右侧的卡住表列

html - 在不缩进盒模型的情况下缩进无序列表

css - 响应式菜单中一致的列表项高度

javascript - 使用 javascript 显示 [object HTMLUListElement] 的内容

html - 子菜单的下拉菜单位置

javascript - 无法拖动动态添加的DIV