Print header/footer on all pages (Print Mode)

前端 未结 4 1857
悲哀的现实
悲哀的现实 2020-12-13 10:38
header
content spanning several pages...
Footer - Fixed at
相关标签:
4条回答
  • 2020-12-13 10:54

    Nisse Engstroms answer is correct. You just need to put the thead and tfoot content inside a tr to make it work.And it also is the best method because when you use absolute positioning in a div to make header and footer it will always overlap with your main body content on the next page.

        
        <table>
        
        <thead>
        <tr> !-- these are important
        <th id="header"> !--- these are important
            !--- content of header here
        </th>
        </tr>
        </thead>
        
        <tbody>
        <tr>
        <td>
        !---- main body here
        </td>
        </tr>
        </tbody>
        
        <tfoot>
        <tr>
        <th id="footer">
        
            !----- content of footer here
        </th>
        </tr>
            </tfoot>
        
            </table>
        

    0 讨论(0)
  • 2020-12-13 10:55

    I think I arrived too late :), but I was looking for something like this, and I found one answer that helps me (source https://www.youtube.com/watch?v=yDgFLysON98). I wrote the div tag before and after the content like this

    <div id="header">Top div content</div>
    
    .
    .
    .
    <div id="footer">Bottom div content</div>
    

    Example:

    <!DOCTYPE html>
    <html>
    <head>``
    <style>
    body {
        background-color: #CCC;
        margin:48px 0px 0px 64px;
    }
    div#header {
        position:fixed;
        top:0px;
        left:0px;
        width:100%;
        color:#CCC;
        background:#333;
        padding:8px;
    }
    div#footer {
        position:fixed;
        bottom:0px;
        left:0px;
        width:100%;
        color:#CCC;
        background:#333;
        padding:8px;
    }
    </style>
    </head>
    <body>
    <div id="header">HEADER</div>
    <h1>Page Heading</h1>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <p>Content placeholder ...</p>
    <div id="footer">FOOTER</div>
    </body>
    </html>
    

    ... I hope this helps.

    0 讨论(0)
  • 2020-12-13 10:59

    If you're willing to switch over to tables for your layout (not necessarily ideal), you can do it with the <thead> and <tfoot> elements. They'll print at the top and bottom of every page:

    <table>
    
      <thead>
         <!-- Will print at the top of every page -->
      </thead>
    
      <tbody>
         <!-- Page content -->
      </tbody>
    
      <tfoot>
         <!-- Will print at the bottom of every page -->
      </tfoot>
    
    </table>
    

    Another option is to use display table-header-group and table-footer-group but cross-browser support isn't great:

    #header {
      display: table-header-group;
    }
    
    #main {
      display: table-row-group;
    }
    
    #footer {
      display: table-footer-group;
    }
    
    0 讨论(0)
  • 2020-12-13 11:00

    For that you need to use the mso (microsoft office css properties) in your style:

    <style><--
    @page 
    {
        size:21cm 29.7cmt;
        margin:1cm 1cm 1cm 1cm; 
        mso-title-page:yes;
        mso-page-orientation: portrait;
        mso-header: header;
        mso-footer: footer;
    }
    @page content {margin: 1cm 1cm 1cm 1cm;}
    div.content {page: content;}
    </style>
    
    0 讨论(0)
提交回复
热议问题