tags:

views:

43

answers:

3

I need to create a large table of contents for an HTML book but I can't decide what's the best solution for its markup. I have two options in mind: definitions lists or ordered lists.

Would you consider this a personal style decision? And how about semantics?

I like my list to be numbered but I have problems using "ol" with nestes lists. I guess I'd do the same thing I did with my definition lists by numbering manually (and disabling style in my list).

I thought of these two:

Option A:

<div class="TOC">
    <dl>
        <dt><a href="#">Preface</a></dt>
        <dt>I. <a href="#">Chapter 1</a></dt>
        <dd>
            <dl>
                <dt>1 <a href="#">Section 1</a></dt>
                <dd>
                    <dl>
                        <dt>1.1 <a href="#">Subsection A</a></dt>
                        <dt>1.2 <a href="#">Subsection B</a></dt>
                        <dt>1.3 <a href="#">Subsection C</a></dt>
                    </dl>
                    <dt>2 <a href="#">Section 2</a></dt>
                </dd>
            </dl>
        </dd>
    </dl>
</div>

Option B:

<div class="TOC">
    <ol>
        <li><a href="#">Preface</a></li>
        <li><a href="#">Chapter 1</a>
            <ol>
                <li><a href="#">Section 1</a>
                    <ol>
                        <li><a href="#">Subsection A</a></li>
                        <li><a href="#">Subsection B</a></li>
                        <li><a href="#">Subsection C</a></li>
                    </ol>
                </li>
                <li><a href="#">Section 2</a></li>
            </ol>
        </li>
    </ol>
</div>
+2  A: 

Ordered list is the correct markup. Using a definition list would imply that the major section title is a term which is defined by the titles of its subsections, which is not quite correct.

Rex M
Thanks! I agree.
expora
+2  A: 

100% I'd go with ordered list. This is exactly what they were put into the language for. Using definition lists is an abuse of the language, just because their default rendering is somewhat like you want to see. (Use CSS to make it like right)

What problem are you having with nested ordered lists? (You aren't even supposed to nest DLs)

James Curran
I'm fairly sure nesting DLs is perfectly valid - DDs, like LIs, are flow elements, so can have DLs as children.
lucideer
Thanks! I agree.About the nested lists well... I get numbers like 1, 2, 3 for sections and 1, 2, 3 for subsections instead of numbers like 1.1, 1.2, 1.3. I guess I could do it manually and use "ul" or leave "ol" with no list style.
expora
You don't need to number sub-sections manually - you can do it automatically with CSS.
lucideer
@lucideer: I didn't say you couldn't -- just that you were *supposed to*, that is, it's semantically meaningless.
James Curran
In this particular example it would, for the reason stated by Rex. Nested DLs are not inherently un-semantic though. For example, in a <dd/> defining a term, one could have a <dl/> listing <dt>variation</dt>s - and that's just IF you restrict it to definitions, which you needn't by any means.
lucideer
+2  A: 

Definition lists are NOT strictly for "definitions" as some people seem to be saying - if they were they would have extremely few uses. However, while <dl/>s are very flexible and have many uses, the ordered-list does seem like a better option here.

If you're trying to number nested lists (whether they're nested <ol/>s or <dl/>s), you can use CSS counter-increment and counter-reset properties to add numbers automatically based on the nested depth, rather than maintaining the numbering manually for every revision.

Example:

.TOC ol{
  list-style-type:none;
  counter-reset:toc1;
}

.TOC ol li::before{
  content:counter(toc1)' ';
  counter-increment:toc1;
}

.TOC ol li ol{
  counter-reset:toc2;
}

.TOC ol li ol li::before{
  content:counter(toc1)' .'counter(toc2)' ';
  counter-increment:toc2;
}

.TOC ol li ol li ol{
  counter-reset:toc3;
}

.TOC ol li ol li ol li::before{
  content:counter(toc1)' .'counter(toc2)' .'counter(toc3)' ';
  counter-increment:toc3;
}
lucideer
Great, thank you! I haven't made use of these properties before and they will sure help in maintaining my code.
expora