html - 在列表前添加文本

标签 html css pseudo-element html-lists

我正在尝试制作一个列表
元素1.鸟
元素2.狮子
...

问题是我不想为每个元素都写“元素”。有什么方法可以将内容添加到我的列表中吗?

最佳答案

你需要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>

关于html - 在列表前添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258070/

相关文章:

javascript - 使用 JavaScript 和 HTML5 显示隐藏图像(与现有帖子相关)?

html - 如何使用 Bootstrap 制作带有背景图像的 div 全屏

javascript - 除非重新加载页面,否则滚动事件不起作用

javascript - 即使将 STATICFILES_DIR 设置为正确的路径,Django 静态文件也不会加载

jquery - 使用 `.css` 作为伪元素

css - 在所有浏览器中覆盖占位符字体 css

javascript 无法在 <ons-template> 中工作 - onsen ui

php - PHP 中的 HTML 净化

jquery - script-tutorials.com Colorwheel改变不同div的颜色

javascript - 悬停在不同元素上时触发 Anchor::after Pseudo Content