UL List items with styled decimal numbers

Nit*_*esh 3 html css css3

I need to create a set of list items where I need to style the list item numbers (decimals) with a border-radius and a background color.

Here is the snapshot of how I want my list items to look like.

图像是我正在寻找的.

I have tried to put a border radius, background on the li, but I was not able to get the output that I am lookin for.

Here is a WORKING LINK of what I have tried so far. I removed the border-radius, background, etc. as it was not displaying properly.

The HTML:

<ul>
    <li>Text Character</li>
    <li>Text Character</li>
    <li>Text Character</li>
    <li>Text Character</li>
    <li>Text Character</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

The CSS:

li{list-style-type:decimal;}
Run Code Online (Sandbox Code Playgroud)

I would like solutions for the above provided the below..

  • It should not be a sprite/background image solution
  • I am only looking for a solution where I have to use a border-radius and background-color on the list items, which I tried, but could not work the way I want in my reference Image.

Awaiting Solutions.

Jon*_*ann 6

这是一个小技巧:

ol {
        counter-reset: item;
        margin-left: 0;
        padding-left: 0;
    }
li {
        display: block;
        margin-bottom: .5em;
        margin-left: 2em;
    }
li:before {
        display: inline-block;
        content: counter(item) "";
        counter-increment: item;
        background: blue;
        color: white;
        display: inline-block;
        border-radius: 50%;
        margin: 0 5px ;
        padding: 0 5px;
    
    }
Run Code Online (Sandbox Code Playgroud)
<ol>
  <li>Item1</li>
  <li>Item2</li>
  <li>Item3</li>
  <li>Item4</li>
</ol>
Run Code Online (Sandbox Code Playgroud)

  • 此外,并不意味着口碑,但如果子弹数字的_length_变得太大,这形状就像一个_pill _... :) (2认同)
  • 你是对的Joum,但如果这个名单真的很长怎么办?你想要一个有4个数字的巨大圆圈,或者你更喜欢吃药吗?我很尊敬,我更喜欢吃药 (2认同)