html - 如何在列表编号中添加单词前缀

标签 html css html-lists pseudo-element

因此,我四处搜索,但未能找到一个看似简单问题的答案。

我有一个这样的有序列表:

<ol>
  <li>Some text here</li>
  <li>Some more text here..</li>
  <li>Oh yeah, here's some pretty text</li>
</ol>

显示:

  1. Some text here
  2. Some more text here..
  3. Oh yeah, here's some pretty text

我真正想展示的是:

Step 1. Some text here

Step 2. Some more text here..

Step 3. Oh yeah, here's some pretty text

问题:这是否可能?如果可能,我将如何在不使用有问题的解决方案的情况下进行?

最佳答案

您可以使用::before(:before for IE8)和counter-reset/increment

ol {
  counter-reset: number;
}
li {
  list-style: none;
  counter-increment: number;
}
li::before {
  content: "Step " counter(number) ".";
  position: relative;
  left:-5px
}
<ol>
  <li>Some text here</li>
  <li>Some more text here..</li>
  <li>Oh yeah, here's some pretty text</li>
</ol>

关于html - 如何在列表编号中添加单词前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35352339/

相关文章:

javascript - 来自一个 <ul>、CSS 和一些 JS 的多个列列表

java - 如何单击列表 selenium2 中的链接

html - 为什么我们必须为 css 文件使用 "link"标签

html - 从无序列表 <ul> 中删除 "bullets"

html - 悬停按钮上出现闪烁的黑色边框?

javascript - 到达新的 div 时停止粘性 div

javascript - 页面缩放时可使用哪些事件

javascript - 仅在 IE 中显示 div

html - 如何使用 Flexbox 进行两列布局并且列中元素之间的间距相同?

css - 根据语言更改字体