In my html
code I have the following list defined:
<p class="list">first.</p>
<p class="list">second.</p>
Now, in css
I have:
.list {
display: table;
}
.list:before {
display: table-cell;
counter-increment: counter;
content: counter(counter) '.';
padding-right: 5px;
}
and the result on the page is:
1. first
1. second
How can I increment the second number to the value of 2?
You should be using counter-reset
property on the wrapper of the list
s - see demo below:
body {
counter-reset:counter;
}
.list {
display: table;
}
.list:before {
display: table-cell;
counter-increment: counter;
content: counter(counter) '.';
padding-right: 5px;
}
<p class="list">first.</p>
<p class="list">second.</p>
Instead of wrapping your HTML in <p>
tags, you could use:
<ol>
<li>first</li>
<li>second</li>
</ol>
This will give you the output desired.
Here is a working fiddle.
This way you don't need to do any count stuff in CSS, much easier, simpler solution and compatible cross browser.
You need to reset the counter:
body {
counter-reset: section;
}
.list {
display: table;
}
.list:before {
display: table-cell;
counter-increment: section;
content:counter(section) ". ";
padding-right: 5px;
}
<p class="list">first.</p>
<p class="list">second.</p>
body {
counter-reset: section;
}
h1 {
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
<h1>HTML tutorials:</h1>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h1>Scripting tutorials:</h1>
<h2>JavaScript</h2>
<h2>VBScript</h2>
<h1>XML tutorials:</h1>
<h2>XML</h2>
<h2>XSL</h2>
Source: http://www.w3schools.com/css/css_counters.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With