【发布时间】:2018-08-26 03:20:09
【问题描述】:
我的示例中的 CSS 计数器不会增加,尽管我已指定它这样做。我在这里阅读了一些关于可能导致此问题的元素嵌套级别的问题,但在我的情况下,所有元素都处于同一级别。
MWE
<!DOCTYPE html>
<head>
<style>
body {
counter-reset: firstCounter;
counter-reset: secondCounter;
}
h2.heading::before {
counter-increment: firstCounter;
content: counter(firstCounter)"\00a0";
}
h3.issue::before {
counter-increment: secondCounter;
content: counter(secondCounter)"\00a0";
}
</style>
</head>
<body>
<h1>The Book</h1>
<h2 class="heading">First Heading</h2>
<h3 class="issue">The Issue of Drinking</h3>
<h3 class="issue">The Issue of Drinking Too Much</h3>
<h2 class="heading">Second Heading</h2>
<h3 class="issue">The Issue of Driving</h3>
<h3 class="issue">The Issue of Drunk Driving</h3>
</body>
</html>
结果
标题“第二标题”的计数器必须为“2”。在 CSS 中交换 body 标记下的 counter-reset 的顺序会导致相同的问题,但会与受影响的标题相反。
【问题讨论】:
-
哈立德你好。您应该将 css 中的 body 标签更改为:body { counter-reset: firstCounter secondCounter; } 这应该可以解决问题。
标签: css css-counter