Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating table of contents in html

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
    .....

I have the following but each subsection restarts from 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

like image 391
Thomas Buckley Avatar asked Jan 03 '13 11:01

Thomas Buckley


People also ask

How do you create a table with 3 rows and 5 columns in HTML?

You first declare the table with the <table> markup, and then the rows with the <tr> markup. (table row.) Inside each row, you can declare the data containers <td> . (table data).

How do you create a table with 3 columns and 3 rows in HTML?

Creating Tables in HTML You can create a table using the <table> element. Inside the <table> element, you can use the <tr> elements to create rows, and to create columns inside a row you can use the <td> elements. You can also define a cell as a header for a group of table cells using the <th> element.

What kind of content can you put into HTML tables?

They can contain all sorts of HTML elements; text, images, lists, other tables, etc.


2 Answers

This can indeed be done with pure CSS:

ol {
    counter-reset: item;
}

li {
    display: block;
}

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

Same example as a fiddle.

like image 123
jasonkarns Avatar answered Oct 24 '22 16:10

jasonkarns


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

  • Look at this one for starters

  • Another one here, with ordered lists

like image 23
robasta Avatar answered Oct 24 '22 15:10

robasta