How to use HTML to print header and footer on every printed page of a document?

前端 未结 20 1376
迷失自我
迷失自我 2020-11-21 16:51

Is it possible to print HTML pages with custom headers and footers on each printed page?

I\'d like to add the word \"UNCLASSIFIED\" in Red, Arial, size 16pt to the t

20条回答
  •  囚心锁ツ
    2020-11-21 17:14

    the magic solution is really putting every thing in single table.

    • thead: this is for the repeated header.

    • tfoot: the repeated footer.

    • tbody: the content.

    and make a single tr, td and put every thing in a div

    CODE::

    ...
    ...

    table.report-container {
        page-break-after:always;
    }
    thead.report-header {
        display:table-header-group;
    }
    tfoot.report-footer {
        display:table-footer-group;
    } 
    

    extra: to prevent overlapping with multiple pages. like:

    ...
    ...
    ...
    ... ... ...

    which results in overflow that will make things overlap with the header within the page breaks..

    so >> use: page-break-inside: avoid !important; with this class article.

    table.report-container div.article {
        page-break-inside: avoid;
    }
    

    pretty simple, hope this will give you the best result you wishing for.

    best regards. ;)

    source..

提交回复
热议问题