Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning an unordered list into a table of contents

Reference this fiddle: http://jsfiddle.net/exGnZ/

Hi, I'm trying to reproduce a table of contents with an unordered list and leader dots. Unfortunately, when there's a long line of content, the formatting breaks down. Does anyone know how to get Chapter 2 in the image below to appear on the same line as the dots?

enter image description here

Here's the code I've got at the moment: http://jsfiddle.net/exGnZ/

I'm also pasting it here:

    <div>
    <ul id="toc">
    <li><span>Introduction</span> <a href="#">Chapter 1</a></li>
    <li><span> Storm clouds looming Storm clouds looming Storm clouds looming Storm clouds looming Storm clouds looming</span> <a href="#">Chapter 2</a></li>
    <li><span>Sun breaks</span> <a href="#">Chapter 3</a></li>
    <li><span>Lost and confused</span> <a href="#">Chapter 4</a></li>
    <li><span>The pot of gold</span> <a href="#">Chapter 5</a></li>
    <li><span>Nom nom nom</span> <a href="#">Chapter 6</a></li>
    </ul></div>

And the CSS:

    div {padding:10px;}
    #toc {
        list-style: none;
        margin-bottom: 20px;
    }
    #toc li {
        background: url(http://5thirtyone.com/sandbox/share/toc/dot.gif) repeat-x bottom left;
        overflow: hidden;
        padding-bottom: 2px;
    }
    #toc a,
    #toc span {
        display: inline-block;
        background: #fff;
        position: relative;
        bottom: -4px;
    }
    #toc a {
        float: right;
        padding: 0 0 3px 2px;
    }
    #toc span {
        float: left;
        padding: 0 2px 3px 0;
    }
like image 214
Fred Avatar asked Jan 17 '12 16:01

Fred


People also ask

Can you display an unordered list as a table?

You cannot make CSS do HTML work. What you can do, however, is styling your unordered list so that it will be represented as table. I would just ask you: Why do you want to use ul/li instead of a standard table? Because if the data you have in that list is tabular data, you SHOULD use a table.

How do you make an unordered list table in HTML?

Use the <ul> tag together with the <li> tag to create unordered lists. Tip: Use CSS to style lists. Tip: For ordered lists, use the <ol> tag.

How do you create an unordered list a list with the list?

To create unordered list in HTML, use the <ul> tag. The unordered list starts with the <ul> tag. The list item starts with the <li> tag and will be marked as disc, square, circle, etc. The default is bullets, which is small black circles.

What are the 3 types of unordered list?

There are three types of lists in HTML: Unordered list or Bulleted list (ul) Ordered list or Numbered list (ol) Description list or Definition list (dl)


1 Answers

How about this: http://jsfiddle.net/exGnZ/40/

Best I could manage in the time I had.

like image 121
Deadlykipper Avatar answered Oct 24 '22 10:10

Deadlykipper