如何用css实现如下效果

div如下:

<div id="page">
    <h1>Heading Title</h1>
    <h2>Subheading Title</h2>
    <h2>Subheading Title</h2>
    <h1>Heading Title</h1>
    <h2>Subheading</h2>
    <h1>Heading Title</h1>
</div>

要实现的效果如下:

1) Heading Title
1.1) Subheading Title
1.2) Subheading Title

2) Heading Title
2.1) Subheading Title

3) Heading Title
阅读 1.8k
1 个回答
#page {
    counter-reset: section;
}

h1 {
    counter-reset: subsection;
}

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

h2:before {
    counter-increment: subsection;
    content: counter(section) "." counter(subsection) ") ";
}

参考:
CSS counter-increment

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题