仅在最后打印的页面中打印页脚以进行介质打印

nik*_*esh 7 css printing

我需要打印多个页面和页脚需要打印在最后一页底部.我已经为这样的页脚添加了css

footer {
     display: block;
     width:100%;        
     position:absolute;
     left:0;
     bottom:0px;        
}
Run Code Online (Sandbox Code Playgroud)

问题是页脚是打印第一页,但我需要在最后一页.

4dg*_*rav 0

包含一个样式表,其中包含您自定义的页脚样式,以便使用media="print"as进行打印

\n\n
<link rel="stylesheet" href="yourpath/footerstyle.css" media="print"/>\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者

\n\n

像在 html 中一样嵌入样式

\n\n
<style>\n@media print {\n   footer {\n    display: block;\n    width:100%;        \n    position:absolute;\n    left:0;\n    bottom:0;        \n   }\n}\n</style>\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者

\n\n
<style type="text/css" media="print">\n    footer {\n        display: block;\n        width:100%;        \n        position:absolute;\n        left:0;\n        bottom:0;         \n    }\n</style>\n
Run Code Online (Sandbox Code Playgroud)\n\n

尝试将正文定位为相对位置,将页脚定位为绝对位置:

\n\n
<style type="text/css" media="print">\n     body {\n        position: relative;\n     }\n     footer {\n        display: block;\n        width:100%;        \n        position:absolute;\n        left:0;\n        bottom:0;         \n     }\n</style>\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者你可以使用这样的东西:

\n\n
@page:last {\n    @bottom-center {\n        content: "\xe2\x80\xa6";\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

CSS 3 分页媒体模块

\n\n

编辑

\n\n
<style type="text/css" media="print">\n     body {\n        position: relative;\n        margin: 0;\n     }\n     .page-section {\n\n        /* Specify physical size of page, margins may vary by browser */\n\n        height: 10 in; /* or give size as per proper calculation of the height of all your pages after which you want footer */\n        position: relative;\n     }\n     footer {\n        display: block;\n        width:100%;        \n        position:absolute;\n        left:0;\n        bottom:0;         \n     }\n</style>\n
Run Code Online (Sandbox Code Playgroud)\n\n

.page-section根据您希望每页打印的 div添加到相关的 div / div 或直接添加到body标签。

\n