Adding text before list

后端 未结 1 962
無奈伤痛
無奈伤痛 2020-12-04 02:09

I am trying to make a list like
Element 1. bird
Element 2. lion
...

The problem is I don\'t want to write \"Element\" for every item. Is there any way

相关标签:
1条回答
  • 2020-12-04 02:29

    You need CSS counters:

    #customlist {
      /* delete default counter */
      list-style-type: none;
      /* create custom counter and set it to 0 */
      counter-reset: elementcounter;
    }
    
    #customlist>li:before {
      /* print out "Element " followed by the current counter value */
      content: "Element " counter(elementcounter) ": ";
      /* increment counter */
      counter-increment: elementcounter;
    }
    <ol id="customlist">
      <li>Elephant</li>
      <li>Bird</li>
      <li>Lion</li>
    </ol>

    0 讨论(0)
提交回复
热议问题