html – CSS Counter Increment不起作用

前端之家收集整理的这篇文章主要介绍了html – CSS Counter Increment不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的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;
}

和反增量应该只包含标题

.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>
原文链接:https://www.f2er.com/html/225074.html

猜你在找的HTML相关文章