Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML + CSS: Ordered List without the Period?

I think the answer to this question is no... but does anyone know of a an HTML/CSS way to create an ordered list without a period after the numbers? Or, alternatively, to specify the separator character?

Ideally I don't want to do list-style-image with a different class for each number, but that's all I've been able to think of so far... That seems terribly unsemantic.

IE:

Default Style: 1. ______ 2. ______ 3. ______  Desired Style: 1  ______ 2  ______ 3  ______  Alternate Style: 1) ______ 2) ______ 3) ______ 
like image 859
Andrew Avatar asked May 10 '11 04:05

Andrew


People also ask

How do you skip a number in an ordered list in HTML?

You can make the list skip some numbers in a list with the value attribute. This can be done inside the <li> tag, which will change that individual list item to the number your designate to it. All list items after it will be numbered upwards from that number.

Is the default bullet of an ordered list in HTML?

The values that can be used for the list-style-type property for unordered lists are disc (the default bullet shape), square, circle, or none (no bullets are displayed).

How do you display an ordered list in HTML?

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.


2 Answers

This is perfectly possible to do with just CSS (2.1):

ol.custom {   list-style-type: none;   margin-left: 0; }  ol.custom > li {   counter-increment: customlistcounter; }  ol.custom > li:before {   content: counter(customlistcounter) " ";   font-weight: bold;   float: left;   width: 3em; }  ol.custom:first-child {   counter-reset: customlistcounter; } 

Keep in mind that this solution relies on the :before pseudo-selector, so some older browsers -- IE6 and IE7 in particular -- won't render the generated numbers. For those browsers, you'll want to add an extra CSS rule that targets just them to use the normal list-style:

ol.custom {   *list-style-type: decimal; /* targets IE6 and IE7 only */ } 
like image 98
Chris Avatar answered Oct 12 '22 23:10

Chris


Here is the solution

Number nested ordered lists in HTML

All you have to to is change a little bit here

ol li:before {                 content: counter(level1) " "; /*Instead of ". " */                 counter-increment: level1;             } 

^^

like image 38
Kent Avatar answered Oct 13 '22 00:10

Kent