简体   繁体   English

创建页脚,但在每个页面中与打印文档中的CSS不同

[英]Make a footer but in every page different with CSS in a printed document

I would like to print a different footer on each page of my document (because I have to display the page number). 我想在文档的每一页上打印不同的页脚(因为我必须显示页码)。

I tried this CSS but it put every footer one over the other instead of changing it on every page : 我尝试了这个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 HTML

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

So the final html would be: 因此,最终的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>

How can I do it with CSS? 我该如何使用CSS? I don't care if is not supported on every browser but it has to work in Chrome. 我不在乎每种浏览器均不支持该功能,但它必须在Chrome中运行。

Thanks 谢谢

If you can change your HTML a bit, then you can do this with HTML data attributes and css 如果您可以稍微更改HTML,则可以使用HTML数据属性和CSS

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

After hours of researching I found how to do it: CSS: 经过数小时的研究,我发现了如何做:CSS:

section {
    position: relative; 
    height: 95%;
}

Html: HTML:

<section>
    <div style="position: absolute; bottom: 0px; right:20px;"><small>Page {{page}}/{{totalPages}}</small></div>
</section>

try this: 尝试这个:

html: HTML:

<div class="divFooter">{{page}}/{{totalPage}}</div>

css: CSS:

@media print 
  {
   div.divFooter 
     {
       position: fixed;
       bottom: 0;
     }
  } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM