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.开发者_如何学Go I've also tested the browser's margin options and that's not the problem.
Any ideas?
You want display:none
not visibility:hidden
. The latter makes the element invisible, but doesn't remove it from the document flow.
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.
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
}
Use display:none;
Try using display: none;
instead.
use display:none; as you want to display only print and no part of body.
Even visibility:collapse;
does it! :)
精彩评论