I want to create a counter or numbering system in HTML and CSS, but the sub-counter isn’t working properly.
This is what i have done so far, im gonna make a new counter in body and then a sub-counter in a class name second and then increase each of them in Pseudo-elements.
body {
counter-reset: css-counters 0;
}
.first {
position: relative;
left: 90px;
top: 10px;
right: auto;
bottom: auto;
padding: 10px;
}
.first:before {
counter-increment: css-counters;
content: "Điều " counter(css-counters) " ";
position: absolute;
left: -60px;
top: 0;
}
.first .second {
counter-reset: sub-counter;
position: relative;
}
.first .second:first-child {
counter-reset: sub-counter;
}
.first .second:not(:first-child) {
counter-increment: sub-counter 0;
}
.first .second:before {
counter-increment: sub-counter;
content: counter(css-counters) "." counter(sub-counter) " ";
position: absolute;
left: -60px;
top: 0;
}
<body contenteditable="true">
<div class="first">
CẤP HẠN MỨC TÍN DỤNG:
<div class="second">
<span id="dieu1_key4" class="bold">Hạn Mức Tín Dụng:</span>
<span id='dieu1_key5'>...</span>
</div>
<div class="second">
<span id="dieu1_key4" class="bold">Hạn Mức Tín Dụng:</span>
<span id='dieu1_key5'>...</span>
</div>
</div>
<div class="first">
CẤP TÍN DỤNG THEO HẠN MỨC TÍN DỤNG
</div>
</body>
2
Answers
I found the solution: just a minor change in css
You are defining your sub-counter to increment by 0. Here’s the fixed code.