2012-12-30 133 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