2012-12-30 127 views
12

我有一个web应用程序,它有一个可能超过一页的报告,我想在每个页面中打印页眉和页脚。 我找到并试试这个: Repeating a report header in each page 但它并没有为我工作。我尝试歌剧,IE9,Firefox,谷歌浏览器但...没什么。页边距工作正常,但内容是我想要的,它不'工作。页面和页脚在打印模式下使用css的每个页面

+0

可能出现[如何使用HTML在文档的每个打印页上打印页眉和页脚?](http://stackoverflow.com/questions/1360869/how-to-use-html-to-print- header-and-footer-on-every-printed-page-of-a-document) – Quentin

回答

13

您可以设置position: fixed;页眉和页脚,以便它会重复每一页上

对于实例

<header class="onlyprint"><!--Content Goes Here--></header> 
<footer class="onlyprint"><!--Content Goes Here--></footer> 

@media screen { 
    header.onlyprint, footer.onlyprint{ 
     display: none; /* Hide from screen */ 
    } 
} 

@media print { 
    header.onlyprint { 
     position: fixed; /* Display only on print page (each) */ 
     top: 0; /* Because it's header */ 
    } 
    footer.onlyprint { 
     position: fixed; 
     bottom: 0; /* Because it's footer */ 
    } 
} 
+0

它可以在webkit上运行吗? –

+0

@PauFracés它以前不支持,不确定当前状态,我曾用它作为firefox的方式,所以认为这可能会帮助他 –

+0

我正在处理同一主题,但需要它在webkit上工作。我一直无法用html + css做到这一点,所以我现在正在javascirpt库中工作,以完成工作。因此我的兴趣 –

5

我真的很感谢你的回复,但我已经使用这个解决方案(位置:固定的)前并且页面的内容将被标题屏蔽。所以我必须使用“@page”,它只适用于“保证金”属性和“内容”不起作用或换句话说我无法达到我想要的结果。

+3

它将使用'position:fixed'。例如,如果将* @ page:margin-top:2mm *的页边距设置为* html:margin-top:20mm *,并将您的固定标题设置为* header:margin:0 *,则将html页面设置为潮湿。这会将您的固定标题放在2毫米的页边距上,而页面内容将保留20毫米的页边距。即使打印出来也没有重叠。 – frequent

+0

谢谢!这个评论为我做了! –

+0

'html'保证金是一个聪明的把戏。作品膨胀。你知道我是否可以更改每个印刷页面? – ppumkin