CSS Counter Increment不起作用

Ren*_*unt 7 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;
}
Run Code Online (Sandbox Code Playgroud)
<ul class="moving-steps">
  <li></li>
  <li></li>
  <li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

此代码无效.

 counter-increment: headings 1;  
 content: counter(headings, decimal); 
Run Code Online (Sandbox Code Playgroud)

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

小智 13

你应该有ul自己的css :

.moving-steps {
    counter-reset: headings;
}
Run Code Online (Sandbox Code Playgroud)

并且counter-increment应该只包含headings:

.moving-steps > li:before {
    counter-increment: headings;
}
Run Code Online (Sandbox Code Playgroud)

看看这个JS小提琴:

.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;
}
Run Code Online (Sandbox Code Playgroud)
<ul class="moving-steps">
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ul>
Run Code Online (Sandbox Code Playgroud)