Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you style ordered list numbers?

I'm trying to style the numbers in a ordered list, I'd like to add background-color, border-radius and color so they match the design I'm working from:

enter image description here

I guess it's not possible and I'll have to use different images for each number i.e.

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

Is there a simpler solution?

like image 915
Pixelomo Avatar asked May 12 '14 13:05

Pixelomo


People also ask

Can you change the style of numbers in an ordered list?

Answer: Type attribute allows us to change the style of numbers in an ordered list. Explanation: The < li > tag includes two attributes – type and value. The type attribute is used to modify the order numbering in the list item.

How do you change the numbering style of an ordered list in HTML?

There is the Type attribute which allows you to change the numbering style, however, you cannot change the full stop after the number/letter. The markup in this answer needs to be fixed. Use lowercase and enclose attribute values in "quotes".

What are the different number style used in an ordered list?

There can be different types of numbered list: Numeric Number (1, 2, 3) Capital Roman Number (I II III) Small Romal Number (i ii iii)

Does an ordered list use numbers?

An ordered list uses numbers or some sort of notation that indicates a series of items. For example, an ordered list can start with number 1, and continue through 2, 3, 4, and so on.


1 Answers

You can do this using CSS counters, in conjunction with the :before pseudo element:

 ol {     list-style: none;     counter-reset: item;   }   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>
like image 157
SW4 Avatar answered Sep 19 '22 05:09

SW4