微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 如何在我的css代码中增加计数器?

参见英文答案 > html – CSS Counter Increment does not work3个
> Create line numbers on pre with CSS only3个
在我的HTML代码中,我定义了以下列表:
<p class="list">first.</p>
<p class="list">second.</p>

现在,我在css中:

.list {
  display: table;
}
.list:before {
  display: table-cell;
  counter-increment: counter;
  content: counter(counter) '.';
  padding-right: 5px;
}

并且页面上的结果是:

1. first
1. second

如何将第二个数字增加到2的值?

解决方法

您应该在列表的包装上使用counter-reset属性 – 请参阅下面的演示:
body {
 counter-reset:counter;
}
.list {
  display: table;
}
.list:before {
  display: table-cell;
  counter-increment: counter;
  content: counter(counter) '.';
  padding-right: 5px;
}
<p class="list">first.</p>
<p class="list">second.</p>

原文地址:https://www.jb51.cc/html/226640.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐