Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header and Body content overlapping while printing webpage with print mode css

Tags:

html

css

I have to print the webpage with customized header in every page, Below is my CSS code for print media

  @media screen {
      header.onlyprint, footer.onlyprint,.watermark{
          display: none; /* Hide from screen */
      }

  }
  @page {
    size:A4;

 }
  @media print {
    @page {
            size:auto;
            margin-top:2mm;

   }
   html{
     margin-top: 20mm;
   }
    header.onlyprint {
        position: fixed; /* Display only on print page (each) */
        top: 0; /* Because it's header */
        margin-top: 0;
    }
  } 

And HTML code is:

 <header class="onlyprint">
      <img src="images/logo.png"/>
 </header>

But the problem is only in first page the logo is printing properly and from second page the logo is getting overlapped with body content.the CSS of HTML is not working from second page.

like image 390
samz22 Avatar asked Jun 08 '17 10:06

samz22


People also ask

Why are my CSS elements overlapping?

This could happen for several reasons, especially when you consider the position problems with divs from one website to another. Similarly, box elements may overlap for a few reasons, ranging from positioning errors to overflow issues and simple float problems.

How do you fix HTML elements being cut off when printing?

Use " overflow: auto " (or maybe " overflow: visible ") instead. Is the element itself, or a container, using " position: absolute " or " position: fixed ". You should use " position: static " (default positioning) for printing.

How do I stop content overlapping in HTML?

Remove position: absolute; . Content won't flow around things that are taken out of normal flow (which is what absolute positioning does).


Video Answer


1 Answers

It seems this task cannot be properly implemented with CSS only.

I found a workaround for IE and Firefox using tables here: http://www.jessicaschillinger.us/2017/blog/print-repeating-header-browser/

Quick summary of that link's content: IE and Firefox will repeat the <thead> Element on every printed page, whereas the <tbody> will be printed continuously without repetition.

like image 145
Patrick Avatar answered Sep 27 '22 17:09

Patrick