1

I'm trying to pretty up my order list items and I'm now wondering how I can achieve the following effect, and if it's even possible in pure CSS:

enter image description here

Is it possible to change the number-points and style them like this in just CSS, and if so, how?

jay_t55
  • 11,362
  • 28
  • 103
  • 174
  • 2
    already discussed here: http://stackoverflow.com/questions/10877/how-can-you-customize-the-numbers-in-an-ordered-list – errand Nov 27 '14 at 12:49
  • Didn't see that when I searched SO. – jay_t55 Nov 27 '14 at 12:50
  • Using background-image is not a solution since the moment the length of the numbers is greater than the width of the image, you're stuffed. – jay_t55 Nov 27 '14 at 13:00

1 Answers1

3

Yes, this is possible with a combination of the :before pseudo element and CSS counter-increment.

The HTML:

<ol>
    <li>Lorem</li>
    <li>Lorem</li>
</ol>

And the CSS:

ol {
    counter-reset: li;
}

li {
    position: relative;
    list-style-type: none;
}

/* Style the before element how you want, the important bits here are the content element and counter-increment */
li:before {
    width: 1.75em;
    height: 1.75em;
    position: absolute; left: 0;        
    margin-right: 12px;       
    content: counter(li);
    counter-increment: li;
}
Jamie Wade
  • 277
  • 3
  • 19
  • Thanks Jamie but this totally blows in IE 11. The numbers overlap the first letter of each list item. And there is no other styling either. – jay_t55 Nov 27 '14 at 12:58
  • 1
    @jay_t55 Sure, that's because I didn't include any styling in my example, I just gave you the code to get it working. Style li:before in any way you want, so looking at your question you can add a background-color, 50% border radius etc etc. – Jamie Wade Nov 27 '14 at 13:00
  • Oh sorry I totally forgot. I need to sleep more. Im' gonna go style it now. :) – jay_t55 Nov 27 '14 at 13:01
  • 1
    @jay_t55 Don't worry, we've all been there! – Jamie Wade Nov 27 '14 at 13:04
  • Just a little mucking around I got http://jsfiddle.net/e56281vj/28/ some circles there. Thanks @Jamie. :) Now I just need to tweak it a little more. – jay_t55 Nov 27 '14 at 13:11