gpt4 book ai didi

html - CSS 计数器递增和计数器重置

转载 作者:行者123 更新时间:2023-11-28 06:04:37 24 4
gpt4 key购买 nike

请有人向我解释为什么我得到“1”,即使重置没有应用于小节计数器。我的意思是我不应该得到 1.1、1.2、1.3 而不是 1.1、1.1、1.1 下的所有 h2 标签相同的 h1 标签?我是学习 CSS 的初学者,如果有人能解释一下,这将对我有很大帮助。在此先感谢。代码是:

<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}

h1 {
counter-reset: section;
}

h1:before {
counter-increment: section;
content: "Section " counter(section) ". ";
}

h2:before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
</style>
</head>

<body>

<p><b>Note:</b> IE8 supports these properties only if a !DOCTYPE is specified.</p>

<h1>HTML tutorials</h1>
<h2>HTML Tutorial</h2>
<h2>XHTML 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>

</body>
</html>

输出: output

最佳答案

请试试这个:

代替

h1 {
counter-reset: section;
}

会是

h1 {
counter-reset: subsection;
}

关于html - CSS 计数器递增和计数器重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com