How to Remove Header and Footer with @media print CSS?

2

I'm using% css of CSS to customize the page at print time, but I'm not able to remove the footer and header created by the own browser

.

I know what to remove for the @media print{} settings, but I do not know how to exit via code with Browser or through javascript?

Here's what I've tried:

header { display: none !important; } 
footer { display: none !important; } 
    
asked by anonymous 03.10.2017 / 16:08

3 answers

1

Paula, try this on your @media print:

@page{size: auto;}
    
03.10.2017 / 16:43
3

In the header and footer case of the browser I know it's possible in the settings:

ButIsawaresponseinSOsayingthatcsswouldhaveeffect:

@page{size:auto;/*autoistheinitialvalue*/margin:0mm;/*thisaffectsthemarginintheprintersettings*/}

Source:

link

If you're talking about a Header or Footer you've created:

You can do this using display : none ;

The CSS property display specifies the type of rendering box used by an element.

Display with none value: Disables element display (without affecting layout); all child elements also have their display disabled.

@media print{
   #noprint{
       display:none;
   }
}

@page{
  size: auto;
  margin: 0mm;
}
<div id="noprint">
    Elemento que será ocultado na impressão...
</div>
    
03.10.2017 / 16:15
1

Create a class within a @media print and place this class on all elements you want to delete at the time of printing.

@media print {

    .no-print{
       display: none;
    }

}

<a href="#" class="no-print"> Link do Rodapé </a>
    
03.10.2017 / 16:14