Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default header for each page by css?

Tags:

html

css

printing

I working with my project for printing some documents.There I met some problem in set header for each print pages ! I want to print the html table that have so many tr ,its separated to two pages when print.Therefore,I want to set thead as header element for each print page.So help me !!

<style type="text/css">
table {
  border: 1px solid #eee;
  width: 100%;
  color : green;
}
th,td {
    border: 1px solid red;
    width: 50px;
    height: 50px;
}
@media print {
body * {visibility: hidden;}
#printable * {visibility: visible;}
#printable th {

    top: 0;
}
}
</style>
<div id="printable">
<span><center>Print Example</center></span>
<table>
    <thead>
        <tr><th>Name</th>
            <th>Salary</th>
            <th>Phone</th>
        </tr>
    </thead>
    <tbody>
        <tr><td>David</td>
            <td>3828</td>
            <td>83939</td>
        </tr>
        <tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr>
        <tr><td>Sheee</td>
            <td>3483939</td>
            <td>111111</td>
        </tr>
        <tr><td>David</td>
            <td>3828</td>
            <td>83939</td>
        </tr>
        <tr><td>David</td>
            <td>3828</td>
            <td>83939</td>
        </tr>
        <tr><td>David</td>
            <td>3828</td>
            <td>83939</td>
        </tr>
        <tr><td>David</td>
            <td>3828</td>
            <td>83939</td>
        </tr>
        <tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr><tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr><tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr><tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr><tr><td>Jone</td>
            <td>39393</td>
            <td>0202022</td>
        </tr>
        <tr><td>Smith</td>
            <td>39000383929</td>
            <td>0101010101</td>
        </tr>
    </tbody>
 </table>
</div>

Here I also want thead to page 2 when print.(Running on Chrome)

enter image description here

like image 612
David Jaw Hpan Avatar asked Mar 22 '16 08:03

David Jaw Hpan


People also ask

How do you repeat a header in CSS?

This can be done setting a CSS property for the thead element of the html table. The property that needs to be set is: display: table-header-group. The following html table will repeat the table header at the top of each pdf page when converted to pdf.

How do you edit a header in CSS?

CSS. Control the look and feel of the header and footer of your site with your CSS. To edit your CSS, click "Edit" at the right of the "Custom Header / Footer CSS" field under the "Appearance" tab of your Management Console.

What is table header group in CSS?

ⓘ thead – table heading group. The thead element represents the block of rows that consist of the column labels (headings) for its parent table element.


1 Answers

Most browser do repeat <thead> & <tfoot> including chrome latest browsers.

still there is way you can make the thead repeat like below.

<thead class="report-header">
   <tr>
      <th>
         <div class="header-info">
         ...
         </div>
      </th>
   </tr>
</thead>

And you need to provide css like:

@media print {
thead.report-header {
   display: table-header-group;
}
}

You can find detail description on below link.

repeat header

like image 147
Sumit Patel Avatar answered Oct 25 '22 21:10

Sumit Patel