html - CSS 计数器增量不起作用

标签 html css

这是我的 CSS 和 HTML:

.moving-steps > li:before {
  background: none repeat scroll 0 0 #8F8888;
  border-radius: 15px;
  color: #FFFFFF;
  counter-increment: headings 1;
  content: counter(headings, decimal);
  display: block;
  float: left;
  font-size: 16px;
  font-weight: bold;
  height: 25px;
  line-height: 26px;
  margin-bottom: 0;
  margin-right: 5px;
  text-indent: 8px;
  width: 25px;
}
<ul class="moving-steps">
  <li></li>
  <li></li>
  <li></li>
</ul>

此代码无效。

 counter-increment: headings 1;  
 content: counter(headings, decimal); 

每次都插入 1,我错过了什么?

最佳答案

你应该在 ul 本身上有这个 css:

.moving-steps {
    counter-reset: headings;
}

counter-increment应该只包含headings:

.moving-steps > li:before {
    counter-increment: headings;
}

看看这个 JS Fiddle :

.moving-steps {
  counter-reset: headings;
  list-style: none;
}
.moving-steps > li:before {
  background: none repeat scroll 0 0 #8F8888;
  border-radius: 15px;
  color: #FFFFFF;
  counter-increment: headings;
  content: counter(headings, decimal);
  display: block;
  float: left;
  font-size: 16px;
  font-weight: bold;
  height: 25px;
  line-height: 26px;
  margin-bottom: 0;
  margin-right: 5px;
  text-indent: 8px;
  width: 25px;
}
<ul class="moving-steps">
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ul>

关于html - CSS 计数器增量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780258/

相关文章:

css - 图像通过桌面上的引导轮播旋转到水平

html - 带有图像的 Bootstrap 自定义导航栏

css - 在 css 中按 ".class"或 "*[class~=box]"定位类有什么区别?

jquery - 将另一个文件中的 HTML 数据 append 到 div

php - JSON 到 PHP 发送/接收带有图像数据的变量

javascript - 尝试使用 Javascript 更改输入的值,出现安全错误

html - 修复 CSS 和 HTML 显示布局

html - 如何在 Bootstrap 按钮内制作响应式文本

javascript - 使用 JS 和 PHP 动态更新 CSS 文件源

javascript - 由于添加 Logo ,单选按钮变得错位