Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achieving sub numbering on ol items html

Tags:

html

Im not sure what its called but is it possible to achieve the format of:

1.

1.1

1.2

1.2.1

1.2.2

1.3

I think thats all, thanks!

like image 261
pakooz Avatar asked Jan 13 '10 16:01

pakooz


People also ask

How do you continue numbering in HTML?

Using counter-increment instead of start If you start a list, then stop to interject some other content, then begin the list again, you could use <ol start="..."> to continue numbering where you left off.

How do you start an ordered list on a different number in HTML?

The start attribute specifies the start value of the first list item in an ordered list. This value is always an integer, even when the numbering type is letters or romans. E.g., to start counting list items from the letter "c" or the roman number "iii", use start="3".

How do you number items in a list in HTML?

Items will be numbered from high to low. start HTML5. This integer attribute specifies the start value for numbering the individual list items. This value is always represented as an Arabic numeral (1, 2, 3, etc.), even when the numbering type is letters or Roman numerals.

What does <ol> mean in HTML?

The <ol> HTML element represents an ordered list of items — typically rendered as a numbered list. Flow content, and if the <ol> element's children include at least one <li> element, palpable content .

How to start numbering elements from the letter D in HTML?

For example, to start numbering elements from the letter "d" or the Roman numeral "iv," use start="4". The specified type is used for the entire list unless a different type attribute is used on an enclosed <li> element.

How to define list items in HTML?

The <li> tag is used to define each list item. Tip: Use CSS to style lists. Tip: For unordered list, use the <ul> tag. Specifies that the list order should be reversed (9,8,7...) The <ol> tag also supports the Global Attributes in HTML. The <ol> tag also supports the Event Attributes in HTML.


1 Answers

Several options, in fact, varying in robustness and support:

  1. Do this in the code that generates the lists. Provided it is generated HTML, after all. Wikipedia does that, for example for their section numbers.
  2. You could write some JavaScript to do it after page loading. Won't work with JavaScript turned off, naturally.
  3. Or you can turn to CSS counters. This is probably the best option, if you don't need to support legacy versions of IE, where it is supported since version 8.

    Counters are "self-nesting", in the sense that resetting a counter in a descendant element or pseudo-element automatically creates a new instance of the counter. This is important for situations like lists in HTML, where elements can be nested inside themselves to arbitrary depth. It would be impossible to define uniquely named counters for each level.

    Example(s):

    Thus, the following suffices to number nested list items. The result is very similar to that of setting 'display:list-item' and 'list-style: inside' on the LI element:

    OL { counter-reset: item }
    OL>LI { display: block }
    OL>LI:before { content: counters(item, ".") ". "; counter-increment: item }
    
like image 167
Joey Avatar answered Sep 23 '22 10:09

Joey