Renish Khunt
Renish Khunt

Reputation: 5824

CSS Counter Increment is not working

This is my CSS and 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>

This code is not working.

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

This inserts 1 every time, what am I missing?

Upvotes: 12

Views: 23131

Answers (2)

Benedikt D Valdez
Benedikt D Valdez

Reputation: 409

You should have this css on the ul itself:

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

and counter-increment should only contain headings:

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

Check out this 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>

Upvotes: 21

Sridhar
Sridhar

Reputation: 31

Just Add the following style additionally

body{counter-reset: headings;}

then the value will be increment

Upvotes: 3

Related Questions