Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Counter Increment is not working

Tags:

html

css

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?

like image 704
Renish Khunt Avatar asked Feb 14 '14 13:02

Renish Khunt


People also ask

What is CSS counter-increment?

Definition and Usage The counter-increment property increases or decreases the value of one or more CSS counters. The counter-increment property is usually used together with the counter-reset property and the content property. Default value: none.

What is counter-reset in CSS?

The counter-reset CSS property resets a CSS counter to a given value. This property will create a new counter or reversed counter with the given name on the specified element. Normal counters have a default initial value of 0.

How do you make a counter in HTML?

Steps to create HTML counter Step 1: Create the simple structure using HTML <div> tags. Step 2: Add CSS to make the counter more attractive. Step 3: To add the small icons (like suitcase, coffee-cup, Smylie, user icon, book and more) with the counter, use the bootstrap cdn link and code.

What does it mean to increment a counter?

The counter-increment CSS property increases or decreases the value of a CSS counter by a given value.


2 Answers

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>
like image 186
Benedikt D Valdez Avatar answered Oct 21 '22 14:10

Benedikt D Valdez


Just Add the following style additionally

body{counter-reset: headings;}

then the value will be increment

like image 38
Sridhar Avatar answered Oct 21 '22 14:10

Sridhar