例如,我的 CSS 如下所示:
.page-number:after { counter-increment: page; }
当显示为内容时,例如 6 页:
.page-number:after {
content: 'Page ' counter(page) ' of';
}
我想存储最后一个计数器 - 6 - 并在每个项目之后打印出来。有可能这样做吗?
ul {
list-style: none;
counter-reset: page;
padding: 0;
}
.page-number {
counter-increment: page;
}
.page-number:before {
content: 'Page ' counter(page) ' of'
}
<p>I want to use counters to print '6' after each item. eg. page 1 of 6 </p>
<ul>
<li class="page-number"></li>
<li class="page-number"></li>
<li class="page-number"></li>
<li class="page-number"></li>
<li class="page-number"></li>
<li class="page-number"></li>
</ul>
我.page-number
的位置是固定的,它将显示在所有打印的页面上。
更新:
@media print {
body { margin: 0; }
thead { counter-reset: pages; }
.page-number:before { counter-increment: pages; content: " "; }
.page-number:after { counter-increment: page; }
.page-number:after { content: "Page " counter(page) " of " counter(pages); }
}