Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printed HTML table don't apply margins in all pages

I have this html:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<style type="text/css">
    table { 
        page-break-inside: auto;
        margin-top: 50mm;
        margin-bottom: 50mm;
    }
    tr    { page-break-inside: auto; page-break-after: auto }
    thead { display: table-header-group;}
    tfoot { display: table-footer-group;}

    #header { 
        position: fixed; 
        width: 100%; 
        top: 0; 
        left: 0; 
        right: 0;
    }
    #footer { 
        position: fixed; 
        width: 100%; 
        bottom: 0; 
        left: 0;
        right: 0;
    }
</style>
</head>
<body>

    <div id="header"> 
        <p>Personalised header</p> 
    </div>
    <div id="footer"> 
        <p>Personalised footer</p> 
    </div> 

    <table>
        <thead>
            <tr><th>heading</th></tr>
        </thead>
        <tfoot>
            <tr><td>notes</td></tr>
        </tfoot>
        <tbody>
        <tr>
            <td>x</td>
        </tr>
        <tr>
            <td>x</td>
        </tr>
        <tr>
            <td>x</td>
        </tr>

        <tr>
            <td>x</td>
        </tr>
        <!-- Mor than 500 similar tr-->
        <tr>
            <td>x</td>
        </tr>
    </tbody>
    </table>
</body>
</html>

It's a big table. The table have top and bottom margins, but only apply margin-top in the first printed page and margin-bottom in the last printed page:

First printed page with padding-top

Middle printed pages without paddings

How can a I resolve this problem? I want the fixed positions of the headers and footers of the page, but the table I want that margins applies in all printed pages.

like image 244
hlastras Avatar asked Jun 29 '18 12:06

hlastras


People also ask

How do I keep html tables from splitting across pages?

Select the table which breaks across two pages, and then click Layout (under Table Tools) > Properties. See screenshot: 2. In the popping out Table Properties dialog box, (1) enable the Row tab, (2) uncheck the Allow row to break across pages option, and (3) click the OK button.

How do I disable margins in html?

Adjusting the Margin Size of an HTML Element With CSS You can remove this margin by setting the top and left margin to zero. Like the padding and border, the sizes of specific sides of the margin can be set using margin-left , margin-right , margin-top , and margin-bottom .

How do I set print margins in html?

One value, like: div {margin: 50px} - all four margins will be 50px. Two values, like: div {margin: 50px 10px} - the top and bottom margins will be 50px, left and right margins will be 10px.

How do you print a table in html?

document. write('<html><head><title>Table Contents</title>'); //Print the Table CSS. var table_style = document.


1 Answers

You can use the @page selector to add spacing around your page like this:

@page { margin: 50px }
like image 142
Furkan Poyraz Avatar answered Oct 14 '22 09:10

Furkan Poyraz