html - 制作页脚,但在打印文档中的每个页面都与 CSS 不同

标签 html css google-chrome printing

我想在文档的每一页上打印不同的页脚(因为我必须显示页码)。

我试过这个 CSS 但是它把每个页脚一个一个放在另一个上面而不是在每个页面上都改变它:

section {
    page-break-before: always;
    margin-top: 30px;
    page-break-inside: avoid;
}
footer {
    bottom:0px;
    height:30;
    right:0%;
    left:0%;
    position:fixed!important;
    position:absolute;
    width=100%;
    top:expression((0-(footer.offsetHeight)+
(document.documentElement.clientHeight?
document.documentElement.clientHeight:
document.body.clientHeight)+(ignoreMe=document.documentElement.scrollTop?
document.documentElement.scrollTop:document.body.scrollTop))+'px');
    text-align:center;
    visibility:visible;
}

HTML

{{# each array}}
    <section class="row">
        ...
        <div class="col-xs-12">
           ...
        </div>
        <footer>
            <small>     Page {{math @index '+' 7 }} </small>
        </footer>
    </section>
{{/each}}

所以最终的 html 将是:

   <section class="row">
        ...
        <div class="col-xs-12">
           ...
        </div>
        <footer>
            <small>     Page 8 </small>
        </footer>
    </section>
   <section class="row">
        ...
        <div class="col-xs-12">
           ...
        </div>
        <footer>
            <small>     Page 9 </small>
        </footer>
    </section>
   <section class="row">
        ...
        <div class="col-xs-12">
           ...
        </div>
        <footer>
            <small>     Page 10 </small>
        </footer>
    </section>

如何使用 CSS 实现?我不在乎是否每个浏览器都支持它,但它必须在 Chrome 中工作。

谢谢

最佳答案

如果你可以稍微改变你的 HTML,那么你可以用 HTML 数据属性和 css 来做到这一点

small::after {
  content: attr(data-page);
}
<footer>
  <small data-page="1">This is page number </small>
</footer>

关于html - 制作页脚,但在打印文档中的每个页面都与 CSS 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45213486/

相关文章:

jquery - 如何使用 jquery 更新选择元素的选项列表?

javascript - 从列表中删除元素列表时,最后剩余的元素不会消失

javascript - 页面加载时触发事件

javascript - 如何使用 CSS 或 JQuery 调整 HTML 选择选项下拉框的大小

javascript - ReactJS 使 <head> html 标签在 react 元素中导入 css/sass 时可见

javascript - 为什么名称验证无效?

google-chrome - 如何让网站可以被 Chrome 搜索到?

html - 如何查看URL的状态?

html - 将文本放在 html 中图像旁边的顶部

html - 两个容器 div 导致侧边栏无法正确 float