Can you sort the ordered list numbers?

I am trying to find a way to put together the numbers in an ordered list, I would like to add a background color, border radius and color to them to match the design I'm working on:

enter image description here

I assume that this is not possible and that I will have to use different images for each number ie

ol li:first-child{list-style-image:url('1.gif')}; ol li:nth-child(2) {list-style-image:url('2.gif');} etc...

I thought I could use sprites to make it a little better, but is there a simpler solution?

+45
html css html-lists sprite
May 12 '14 at 13:17
source share
2 answers

You can do this with CSS counters combined with the :before pseudo-element:

  body { counter-reset: item; } ol { list-style: none; } li { counter-increment: item; margin-bottom: 5px; } li:before { margin-right: 10px; content: counter(item); background: lightblue; border-radius: 100%; color: white; width: 1.2em; text-align: center; display: inline-block; } 
 <ol> <li>item</li> <li>item</li> <li>item</li> <li>item</li> </ol> 
+100
May 12, '14 at 13:20
source share
— -

I was looking for something else and found this example in CodePen;

try the following: http://codepen.io/sawmac/pen/txBhK

 body { font-size: 1.2em; font-family: "Helvetica Neue", Helvetica, sans-serif; margin: 50px; } .custom-counter { margin: 0; padding: 0; list-style-type: none; } .custom-counter li { counter-increment: step-counter; margin-bottom: 5px; } .custom-counter li::before { content: counter(step-counter); margin-right: 20px; font-size: 80%; background-color: rgb(180, 180, 180); color: white; font-weight: bold; padding: 3px 8px; border-radius: 11px; } 
 <ol class="custom-counter"> <li>This is the first item</li> <li>This is the second item</li> <li>This is the third item</li> <li>This is the fourth item</li> <li>This is the fifth item</li> <li>This is the sixth item</li> </ol> 
+15
May 28 '16 at 4:35
source share



All Articles