views:

45

answers:

2

I cannot get an ordered list to show proper indenting. The numbers are all aligned to the right. So the browser (Chrome) shows a space before the single digit numbers and only aligns the double digit numbers correctly to the left.

How can I output a nice ordered list where the numbers are all aligned to the left and the list items all start below each other?

+1  A: 

If you don't mind using absolute positioning, this might work for you.

<style type="text/css">
li {
    list-style-position: inside;
}
.li-content {
    position: absolute;
    left: 80px;
}
</style>

<ol>
  <li><span class="li-content">Test content</span></li>
    (...)
  <li><span class="li-content">Test content</span></li>
</ol>

Note: If you've got anything appearing to the left of the <ol> element on your page (like a floating div), that content will move the numbers to the right, but not the acutal <li> content.

You could also use a whole different technique, with a different markup (nested div elements) with display:table and display:table-cell properties set. That would eliminate the issue with elements appearing on the left, but would require you to utilize the CSS counter property.

Christian Nesmark
Thanks a bunch. That worked great. I just had to remove the padding to the left and now it looks the way I want it to look.
reggie
Uggh. Hmm... it looks okay on a test page. I will not be able to use absolute positioning, though.
reggie
A: 

Actually, the solution is pretty simple, just set

ol {list-style-position: inside;}

And your numbers should "align to the left" like you want.

Josiah Sprague
That aligns the numbers to the left, yes. But the li content is not aligned.
reggie
Well shoot, now you're bein picky. ;) Add some left padding to your li and see if that works. li{padding-left: 4em;}
Josiah Sprague