Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Ordered List (and IE)

I'm looking to generate an output similar to this:

1. One      2. Two      3. Three      4. Four

from the following HTML Code

<ol>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
</ol>

It seems that Internet Explorer does not want to display the number's (list-item's) when you float the li's in order to make them horizontal.

Has anyone run into this and found a solution I can use?

like image 744
Michael Avatar asked Feb 23 '09 20:02

Michael


4 Answers

This code works in all browsers that I have tested. If you have not found an answer yet, the suggestion on the most popular answer is valid. Just adjust your width if you want it to wrap.

<ol style="list-style-type:decimal; width: 600px;">
    <li style="float: left; width: 200px; padding: 2px 0px;">Test</li>
    <li style="float: left; width: 200px; padding: 2px 0px;">Test</li>
    <li style="float: left; width: 200px; padding: 2px 0px;">Test</li>
</ol>

ol.horizontal{
    list-style-type: decimal;
    width: 600px;
}

ol.horizontal li{
    float: left;
    width: 200px;
    padding: 2px 0px;
}

<ol class="horizontal">
    <li>Test</li>
    <li>Test</li>
    <li>Test</li>
</ol>
like image 160
M. Williams Avatar answered Oct 20 '22 15:10

M. Williams


Okay, you need to add a float, width and list-style-type attribute to the css. Looks like this:

li{
    float:left;
    width:50px;
    list-style-type:decimal;
}

Gushiken

like image 29
SvenFinke Avatar answered Oct 08 '22 12:10

SvenFinke


Can you use this CSS?

li  {display: inline}

EDIT: This does not preserve the item numbering, and I'm not aware of any method that does. As a substitute, I guess all you can do is insert the numbers manually, until browsers get better support for CSS counters.

like image 8
David Z Avatar answered Oct 20 '22 17:10

David Z


I've tried every display property on this page and none of them preserve the ordered list numbers when displaying the list horizontally in IE (nor are they preserved in Firefox, Opera or Safari for Windows - and by extension probably Google Chrome, although I admit I didn't test every display property there).

The only solution that (partially - in Firefox only) works is Al W's answer.

I think if you want a horizontal numbered list, you are going to have to generate it on the server or manipulate the list on the client using JavaScript to re-insert the numbers.

like image 4
Grant Wagner Avatar answered Oct 20 '22 15:10

Grant Wagner