I've searched for this but I couldn't find anything similar to my problem.
Basically what I have is a counter called page
and I'm setting up a page counter like this:
content: "Page " counter(page);
that is displayed like this on screen -> Page 1
Everything is working fine, but what I need is to set the page counter to start from 0 instead of 1
I'm using a Wiki (confluence) and I don't have access to where page
is defined, because it's just a variable meant to be used for CSS counters like before.
I tried to following, but with no luck at all:
content: "Page " counter(page) - 1;
content: "Page " counter(page - 1);
content: "Page " calc(counter(page) - 1);
I've also tried to prepend counter-reset
:
counter-reset: page -1;
content: "Page " counter(page);
Now my question is, can I set the counter to start from 0 without using any counter-reset
property? Or, in the previous example where I actually tried to use the counter-reset
, did I make any mistake? Am I missing something?
If you have landed on this page looking for help on usage of CSS counters with the confluence tool, please make note of the comment by Nick:
I wrote a thread in confluence support forum, but apparently what I want to do it's not possible.
Here is one way to make it start from 0 without using counter-reset: [counter-name] -1
. Basically what we are doing is incrementing the counter only from the second occurrence of the div class='page'
so that the counter value for the first instance always remains 0.
counter-reset
does not seem to be a mandatory property*. When there is no reset mentioned, 0 is taken as the default value and the below code still works.
* - Can't find any reference in W3 docs or in MDN that counter-reset
is optional but browsers seem to support it.
body {
counter-reset: page;
}
.page:before {
content: "Page " counter(page);
}
.page ~ .page {
counter-increment: page;
}
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
I have posted the above only for a sample and I don't think it is the correct way to do it. The recommended approach would be the below where while resetting the counter, we set the start value as -1
.
body {
counter-reset: page -1;
}
.page {
counter-increment: page;
}
.page:before {
content: "Page " counter(page);
}
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>