css - 有序列表的自定义列表样式

标签 css html-lists

是否可以为呈现类似内容的有序列表定义样式

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

作为

(1) 元素 1

(2) 元素 2

(3) 元素 3

最佳答案

您可以使用 css counter:before 伪元素来创建这种类型的列表。

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>

关于css - 有序列表的自定义列表样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40467575/

相关文章:

html - Twitter Bootstrap,样式化和使用媒体网格类

html - 调整 CSS 元素以消除叠加

javascript - 错误或成功提交表单时的警报消息

html - 使用 css 格式化 ol 标签中的 li 标签

css - LI 事件数据过滤器不适用于初始页面加载

css - OL-LI 列出 Unicode 中的数字

html - CSS背景分隔线的困难

html - 对齐堆叠 DIV 中的元素

javascript - 使用 JSON 数据在 html 中填充 ul

css - 使用 CSS 设计列表