html - 如何使用 css 计数器增量
问题描述
如何仅在特定段落上使用 css 计数器增量,因为它已应用于我文档中的所有其他段落。
这是我当前的代码:
div.Counter{
counter-reset: my-counter ;
}
h2::before {
content: "Chapter" counter(my-counter) " : ";
counter-increment: my-counter 1;
color: blue;
}
h2{counter-reset: subsection;
}
p::before{
content: counter(my-counter) "." counter(subsection) "." ;
counter-increment: subsection;
color: red;
margin-right: 5px;
}
}
解决方案
尝试为特定段落指定一个类或 id,如下所示:
<p class="counterParagraph">This is a paragraph</p>
并编辑你的 CSS
p.counterParagraph::before{
content: counter(my-counter) "." counter(subsection) "." ;
counter-increment: subsection;
color: red;
margin-right: 5px;
}
推荐阅读
- websocket - Websocket 设计 - 多条路由(许多连接)或处理所有事情的单个路由?
- c# - 如何使用 FluentAssertions 控制字典成员的“平等”
- c# - 单一责任原则和 LINQ to Entity
- javascript - 如何在 javascript 中使用 CryptoJS
- php - PHP - 强制 eval() 在全局范围内运行
- javascript - 节点js需要执行功能
- android - 如何忽略触摸事件,让安卓系统处理?
- android - BottomAppBar 忽略“layout_gravity”,始终显示在顶部
- python - 允许来自我的 zappa 应用程序的“ObjectCreated”事件通知
- javascript - 如何重写此 JavaScript 行以便于阅读?(三元运算符)