Custom list style for ordered lists

2019-02-28 21:34发布

问题:

Is it possible to define a style for an ordered list that renders something like

<ol>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
</ol>

as

(1) Item 1

(2) Item 2

(3) Item 3

回答1:

You can use css counter and :before pseudo-element to create this type of list.

ol {
  counter-reset: custom;
  list-style-type: none;
}

ol li:before {
  content: '('counter(custom)') ';
  counter-increment: custom;
}
<ol>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
</ol>