Reputation: 113
I'm using css to only print a section of a page:
body {
visibility:hidden;
}
.print {
visibility:visible;
background-color: white;
margin: 0;
}
The section above the element I want to print gets properly hidden in the print output, however it still takes up the area of space. I tested this by making a long vertical list of words. In the print output the same area of white space occurs without the words and then the element output occurs. This problem occurs on chrome and mozilla only. I've also tested the browser's margin options and that's not the problem.
Any ideas?
Upvotes: 11
Views: 14711
Reputation: 21
if we want display:inline-block
or display:block
along with visibility hidden.
Then we can use follwing css as a workaround.
{
visibility:hidden
width:0px;
height:0px
}
Upvotes: 2
Reputation: 21199
Use @media
for printing. For example:
@media print {
* {display: none;} /*or if you want only the body*/ body {display: none;}
.print {display: block;}
}
(only a rough example. an actual stylesheet should include all elements of a page instead of wildcards)
Then the stylesheet is only used when printing, or print previewing.
Upvotes: 2
Reputation: 775
use display:none; as you want to display only print and no part of body.
Upvotes: 1
Reputation: 70819
You want display:none
not visibility:hidden
. The latter makes the element invisible, but doesn't remove it from the document flow.
Upvotes: 18