Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide HTML div when printing page

I have a XHTML-based page which contains admin information. The admin should be able to print the page, but I would like it to hide their information.

Is there a way to set a print area when printing a page, or is the only viable solution to open up a secondary page without the admin information when clicking on the "print" button?

Thank you!

like image 826
steeped Avatar asked Aug 31 '12 15:08

steeped


People also ask

How do I hide an element when printing a web page?

The media query is used to hide an element when printing web pages. Use @media print query and set the visibility hidden to that element that needs to hide at printing. Example 1: In this example, hide the element h1 at printing time. To hide the element h1 use media query and set visibility:hidden.

How do I hide a div in HTML?

To hide an element, set the style display property to “none”. document. getElementById("element"). style.

How do I completely hide an element in HTML?

Completely hiding elements can be done in 3 ways: via the CSS property display , e.g. display: none; via the CSS property visibility , e.g. visibility: hidden; via the HTML5 attribute hidden , e.g. <span hidden>

What is @media print in HTML?

This rule allows you to specify different style for different media. So, you can define different rules for screen and a printer. The example below specifies different font families for screen and print. The next CSS uses the same font size for both screen as well as printer.


1 Answers

try this:

<style type="text/css" media="print">
.dontprint
{ display: none; }
</style>

<div class="dontprint">I'm only visible on the screen</div>
like image 159
nickel715 Avatar answered Sep 21 '22 13:09

nickel715