Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header and footer in each page in print mode with css

Tags:

I have a web application and it has a report that might exceed one page and I would like to print a header and footer in every page. i find and try this: Repeating a report header in each page but it didn't work for me.I try opera,IE9,Firefox,Google Chrome but ... nothing.page-margin works fine but content is what I want and it doesn't work.

like image 614
Masoumeh Karvar Avatar asked Dec 30 '12 06:12

Masoumeh Karvar


People also ask

How do I set up headers and footers to print on all pages?

Open the printing preferences dialog box after creating a document in an application. Click the Effects menu on the Detailed Settings tab. Select the Header/Footer check box. Select the items that you want to print on header and footer, Date and Time, Page Number, and Text.

How do I style header and footer in CSS?

Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.


2 Answers

You can set a position: fixed; header and footers so that it will repeat on each page

For Example

<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 */
    }
}
like image 77
Mr. Alien Avatar answered Sep 18 '22 13:09

Mr. Alien


I really appreciate your reply but i have used this solution(position : fixed) before and the content of the page would be masked by the header. so i have to use "@page" which only works with "Margin" property and "Content" does not work or in other words i cannot reach the result i want.

like image 32
Masoumeh Karvar Avatar answered Sep 20 '22 13:09

Masoumeh Karvar