How to remove dot "." after number in ordered list items in OL LI? [duplicate]
Asked Answered
D

1

27

Possible Duplicate:
HTML + CSS: Ordered List without the Period?

Want to remove dot "." from OL (order list)

<ol>
<li>One</li>
<li>Two</li>
</ol> 

Result

 1. One
 2. Two

Required Result

 1 One  
 2 Two
Downstroke answered 14/8, 2012 at 5:9 Comment(1)
See the answer over here. Note, the technique doesn't work in older IE browsers.Martyry
C
47

This will work in IE8+ and other browsers

ol { 
    counter-reset: item;
    list-style-type: none;
}
li { display: block; }
li:before { 
    content: counter(item) "  "; 
    counter-increment: item 
}

or even:

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

If you want older browsers to be supported as well then you could do this (courtesy neemzy):

ol li a {
    float: right;
    margin: 8px 0px 0px -13px; /* collapses <a> and dots */
    padding-left: 10px; /* gives back some space between digit and text beginning */
    position: relative; z-index: 10; /* make the <a> appear ABOVE the dots */
    background-color: #333333; /* same background color as ol ; the dots are now invisible ! */
}
Commander answered 14/8, 2012 at 5:11 Comment(8)
tell more about browser support and accessibilityThibault
@Vladimir Starkov: IE8+, doesn't harm accessibility in any way as it's still an ol.Damle
@VladimirStarkov It's work till IE8 & aboveOatis
@Damle I know it. but it must be included in answer for future usersThibault
May have problems if the text goes over multiple lines. I would suggest the following amendments, as per this stackoverflow answer.Leister
Yes this work, also noticed that we do not require to add list-style-type:none; in OL.Downstroke
@Damle Its work fine in IE8 tooDownstroke
Downside is that this becomes selectable text so not good for number <pre> with code examples.Welcy

© 2022 - 2024 — McMap. All rights reserved.