0

I want to make Header position:fixed. So I've written CSS for .Header { position:fixed; top: 0; left: 0; width: 100%; } in first page there is no problem. If page is more than one then overlapping header by table. I've tried to to give table margin-top but not working.

I want to make header fixed like image down below: I want to make header fixed like image down below

My code:

        <style>
            @page {
              size: 8.27in 5.8in Portrait;
            }

            body {
              font-family: Consolas, Courier, sans-serif;
              font-size: 14px;
              margin: 0;
            }

            label {
              font-weight: 600;
              line-height: 30px;
            }

            ul {
              list-style: none;
              padding: 0;
            }

            table {
              margin: 8px 0;
              width: 100%;
            }

            .printTable table thead {
              background: #ddd;
            }

            .printTable table,
            .printTable th,
            .printTable td {
              border: 1px solid #a9a6a6;
              border-collapse: collapse;
              padding: 5px 8px;
              text-align: left;
            }

            .printTable table tr th:first-child {
              width: 7%;
            }

            .hide {
              display: none;
            }

            .Header h4,
            .Header h2 {
              margin-bottom: 4px;
              margin-top: 4px;
            }

            img {
              width: 130px;
              height: 140px;
            }

            .PrintFoot p {
              margin: 0 0 3px 0;
            }

            .Header {
              position: fixed;
              top: 0;
              left: 0;
              width: 100%;
            }


            /* .printTable {
                   margin-top: 300px !important;
            }*/

            </style>




          <div class="main-div">
                <div class="Header">
                    <div style="overflow: auto;">
                        <div style="width: 20%; float: left;">
                            <img src="https://www.opticcell.com/wp-content/uploads/logo-patriot-250x250.png">
                        </div>

                        <div style="width: 70%; float: left; text-align: center; font-family:'Lato', sans-serif;">
                            <div style="padding-left: 20px;">
                                <h2> {Company} </h2>
                                <h2 style="font-size: 16px;"> {MailName} </h2>
                                <h4> {Address}</h4>
                                <h4> {Phone}</h4>
                                <strong>PAN :</strong> {pan}
                                <h4>{InvoiceCopy}</h4>
                            </div>
                        </div>
                        <div style="width: 20%;"></div>
                    </div>

                    <div style="overflow: auto;">
                        <div style="width: 50%; float: left; text-align:left;">
                            <strong>Invoice No :</strong> {Invoice}
                            <br>
                            <strong>Patient ID :</strong> {PatientID}
                            <br>
                            <strong>Patient Name :</strong> {PatientName}
                            <br>
                            <strong>Age/Sex: </strong> {PatientAge}
                            <br>
                            <strong>Address :</strong> {PatientAddress}
                            <br>
                            <strong>Contact :</strong> {contact}
                            <br>
                            <strong>Party PAN :</strong> {party}
                            <br>
                            <strong>IP no. : </strong> {ipno}
                        </div>

                        <div style="width: 50%; float: left; text-align: right;">
                            <strong>Date :</strong> {Date}
                            <br>
                            <strong>Claim Code :</strong> {ClaimID}
                            <br>
                            <strong>Billing Type :</strong> {Type}
                            <br>
                            <strong>Bill To :</strong> {AccountLedger}
                            <br>
                            <strong>Payment mode :</strong> {Type}
                            <br>
                            <strong>Refer By:</strong> {refer}
                            <br>
                            <strong>Location:</strong> {location}
                        </div>
                    </div>
                </div>

                <div class="MiddlePart">
                    <div class="printTable">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>S.N.</th>
                                    <th>Particular</th>
                                    <th>Qty</th>
                                    <th>Rate</th>
                                    <th>Net Total</th>
                                </tr>
                            </thead>

                            <tbody>
                                <tr>
                                    <td>S.N.</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>1</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>2</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>3</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>4</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>5</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>6</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>7</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>8</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>9</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>10</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>11</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>12</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>13</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>14</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>15</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>16</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>17</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>18</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>19</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>20</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>21</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>22</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>23</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>24</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>25</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>

                                <tr>
                                    <td>26</td>
                                    <td>Particular</td>
                                    <td>Qty</td>
                                    <td>Rate</td>
                                    <td>Net Total</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                    <div style="overflow: auto;">
                        <div style="width: 68%; float: left;">
                            <strong>Pre-Deposit :</strong> {preDepo}
                            <br>
                            <strong>New Deposit :</strong> {newDepo}
                            <br>
                            <strong>New Deposit :</strong> {newDepo}
                            <br>
                            <strong>In Words:  </strong> {InWords}
                        </div>

                        <div style="width: 32%; float: left; text-align: right;">
                            <strong>Bill Total:  </strong> {BillTotal}
                            <br>
                            <strong>Discount  : </strong> {Discount}
                            <br>
                            <strong>Net Total  : </strong> {NetTotal}
                            <br>
                            <strong>Net Total  : </strong> {NetTotal}
                            <br>
                            <strong>Net Total  : </strong> {narration}
                            <br>
                            <strong>Enter By :</strong> {User}
                        </div>
                    </div>
                </div>

                <div class="PrintFoot" style="margin-top: 10px;">
                    <p><strong>Lab Login :</strong> {LoginCredential}</p>
                    <p><strong>Print Date : </strong> Admin {PrintDate}</p>
                    <p style="margin: 15px 0;">
                        <strong>Note : </strong> 
                        If there are any, kindly bring all previous reports and documents on the day of the appointment or treatment. There will be no refunds without original invoice. </p>

                     <p style="text-align: center;">Get Well Soon !!</p>
                </div>
            </div>

            <!-- end snippet -->
theduck
  • 2,589
  • 13
  • 17
  • 23
  • Please review this code,It'll may be help you https://stackoverflow.com/questions/17827908/how-to-make-fixed-header-table-inside-scrollable-div – jaydeep patel Oct 14 '19 at 05:22
  • @jaydeeppatel bro thanks for reply but my question is about invoice print design :::::::::::::::::::::: you can copy and paste my code and Ctrl + P you'll find actual problem – Prince Thapa Oct 14 '19 at 05:34

2 Answers2

0

In your css code you should have to remove one of property position: fixed; from Header claas

.Header {
          position: fixed; **Remove this property from it and check it's working fine for you**
          top: 0;
          left: 0;
          width: 100%;
        }
smita
  • 298
  • 1
  • 4
  • 17
  • yeah it works but if i remove position: fixed; then that header div will not repeat in every page so, unable to remove position: fixed property :::::::::::::::::::: is there any options for repeat header in every page? – Prince Thapa Oct 14 '19 at 06:56
  • Please replace the position: fixed to position: running(header); and check it once and let me know. – smita Oct 14 '19 at 07:25
  • not working ::::::::::::::::::: After i replaced position: fixed to position: running;. In second page there is no Header repeat. – Prince Thapa Oct 14 '19 at 07:40
  • You shoild have replace full text same as i have mentioned ** position: running(header);** – smita Oct 14 '19 at 09:11
  • still not working. Header is showing on first page only but i need to display Header in every page like first page :( ::::::::::::: here is the link of screenshot of second page of print [ https://imgur.com/a/VCHRJcV ] – Prince Thapa Oct 14 '19 at 09:35
0

<style>
    @page {
      size: a4;
      margin: 25px 20px;
    }
    body {
        font-family: Consolas, Courier, sans-serif;
        font-size: 14px;
        margin: 0;
    } 
    .hide {
        display: none;
    } 
    label {
        font-weight: 600;
        line-height: 30px;
    }
    .Header h4,
    .Header h2 {
        margin-bottom: 4px;
        margin-top: 4px;
    }   
    img {
        width: 130px;
        height: 140px;
    }    
    .PrintFoot p {
        margin: 0 0 3px 0;
    }
    .printTable thead th{
        background: #ddd;
    }
    table {
      width: 100% !important;
      max-width: 100%;
      border-spacing: 0;
      border-collapse: collapse;
    }
    .printTable th,
    .printTable td {
        border: 1px solid #a9a6a6;
        padding: 4px 8px;
        text-align: left;
    }      
    
    .printTable table, 
    .printTable tr, 
    .printTable td, 
    .printTable th {
      page-break-inside: avoid;
    }

    .printTable tr {
      page-break-before: auto;
    }


      .printTable td:nth-child(1), .printTable th:nth-child(1) {
        width: 10%;
      }
       .printTable td:nth-child(2), .printTable th:nth-child(2) {
        width: 45%;
      }
      .printTable td:nth-child(3), .printTable th:nth-child(3) {
        width: 12%;
      }
      .printTable td:nth-child(4), .printTable th:nth-child(4) {
        width: 13%;
      }
      .printTable td:nth-child(5), .printTable th:nth-child(5) {
        width: 20%;
      }
    </style>
<table>
      <thead>
        <tr>
          <td>
            <div class="Header" style="overflow: auto; width: 100%;">
              <div style="width: 18%; float: left;">
                <img src="https://www.opticcell.com/wp-content/uploads/logo-patriot-250x250.png">
              </div>

              <div style="width: 64%; float: left; text-align: center; font-family:'Lato', sans-serif;">
                <div style="padding-left: 20px;">
                  <h2> {Company}  </h2>
                  <h2 style="font-size: 16px;">   {MailName}  </h2>
                  <h4> {Address}</h4>
                  <h4> {Phone}</h4>
                  <strong>PAN :</strong> {pan}
                  <h4>{InvoiceCopy}</h4>
                </div>
              </div>
              <div style="width: 18%; float: left;text-align: right;">
                 <strong>Date :</strong> {Date} <br>
              </div>
            </div>

            <div style="overflow: auto; width: 100%; ">
              <div style="width: 50%; float: left; text-align:left;">
                <strong>Invoice No :</strong> {Invoice} <br>
                <strong>Patient ID :</strong> {PatientID} <br>
                <strong>Patient Name :</strong> {PatientName} <br>
                <strong>Age/Sex : </strong> {PatientAge} <br>
                <strong>Address :</strong> {PatientAddress} <br>
                <strong>Contact :</strong> {contact} <br>
                <strong>IP no. : </strong> {ipno}
              </div>

              <div style="width: 50%; float: left; text-align: right;">
                <strong>Party PAN :</strong> {party} <br> 
                <strong>Claim Code :</strong> {ClaimID} <br>
                <strong>Billing Type :</strong> {Type} <br>
                <strong>Bill To :</strong> {AccountLedger} <br>
                <strong>Payment mode :</strong> {Type} <br>
                <strong>Refer By :</strong> {refer} <br>
                <strong>Location :</strong> {location}
            </div>
          </td>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>
              <div class="printTable" style="margin: 5px 0">
                  <table class="table">
                    <thead>
                      <tr>
                        <th>S.N.</th>
                        <th>Particular</th>
                        <th>Qty</th>
                        <th>Rate</th>
                        <th>Net Total</th>
                      </tr>
                    </thead>

                    <tbody>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                       <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                      <tr>
                        <td>S.N.</td>
                        <td>Particular</td>
                        <td>Qty</td>
                        <td>Rate</td>
                        <td>Net Total</td>
                      </tr>
                    </tbody>
                  </table>
              </div>
          </td>
        </tr>
      </tbody>

      <tfoot style="display: table-row-group">
        <tr>
          <td>
            <div>
              <div style="overflow: auto;">
                <div style="width: 68%; float: left;">
                  <strong>Pre-Deposit :</strong> {preDepo} <br>
                  <strong>New Deposit :</strong> {newDepo} <br>
                  <strong>New Deposit :</strong> {newDepo} <br>
                  <strong>In Words:  </strong> {InWords}
                </div>

                <div style="width: 32%; float: left; text-align: right;">
                  <strong>Bill Total:  </strong> {BillTotal} <br>
                  <strong>Discount  : </strong> {Discount} <br>
                  <strong>Net Total  : </strong> {NetTotal} <br>
                  <strong>Net Total  : </strong> {NetTotal} <br>
                  <strong>Net Total  : </strong> {narration} <br>
                  <strong>Enter By :</strong> {User}
                </div>
              </div>

              <div class="PrintFoot" style="margin-top: 10px;">
                <p><strong>Lab Login :</strong> {LoginCredential}</p>
                <p><strong>Print Date : </strong> Admin {PrintDate}</p>
                <p style="margin: 15px 0;"><strong>Note : </strong> If there are any, kindly bring all previous reports and documents on the day of the appointment or treatment. There will be no refunds without original invoice.</p>

                <p style="text-align: center;">Get Well Soon !!</p>
              </div>
            </div>
          </td>
        </tr>
      </tfoot>
</table>