Html 在html中创建目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14138507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:42:05  来源:igfitidea点击:

Creating table of contents in html

htmltableofcontents

提问by Thomas Buckley

Is it possible to create an ordered list like the following? I like this for a table of contents I'm creating.

是否可以创建如下所示的有序列表?我喜欢这个用于我正在创建的目录。

  1. Into
  2. Section1
    2.1 SubSection1
    2.2 SubSection2
  3. Section2
    .....
  1. 进入
  2. Section1
    2.1 SubSection1
    2.2 SubSection2
  3. 第二节
    .....

I have the following but each subsection restarts from 1.

我有以下内容,但每个小节都从 1 重新开始。

<ol>
    <li>
        <a href="#Lnk"></a>
    </li>
    <li>
        <a href="#Lnk"></a>
    </li>
    <ol>
        <li>
            <a href="#Lnk"></a>
        </li>
        <li>
            <a href="#Lnk"></a>
        </li>
    </ol>
</ol>

Thanks

谢谢

采纳答案by jasonkarns

This can indeed be done with pure CSS:

这确实可以用纯 CSS 来完成:

ol {
    counter-reset: item
}
li {
    display: block
}
li:before {
    content: counters(item, ".")" ";
    counter-increment: item
}

Same example as a fiddle: http://jsfiddle.net/N79nP/

与小提琴相同的示例:http: //jsfiddle.net/N79nP/

回答by robasta

There's quite a number of jQuery plugins to generate a table of contents.

有很多 jQuery 插件可以生成目录。

回答by wvp

Have you seen this post: Number nested ordered lists in HTML

您是否看过这篇文章: 在 HTML 中对嵌套有序列表进行编号

I don't think it can be done without using JS.

我认为不使用 JS 是做不到的。