views:

69

answers:

5

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?

+5  A: 

You want display:none not visibility:hidden. The latter makes the element invisible, but doesn't remove it from the document flow.

Skilldrick
Thanks my CSS is weak. I'm guessing it's a bad idea to display: none the whole body? Should I add what I want to print to the page or remove what I don't want?
Cosmin
I think `display:none` on `body` would be a bad idea, but I've never tried it! Probably best to `display:none` on only the non-printing elements (you could add a non-printing class to them in the markup).
Skilldrick
Sounds good thanks.
Cosmin
+1  A: 

Use display:none;

asgerhallas
+1  A: 

Try using display: none; instead.

starskythehutch
+1  A: 

use display:none; as you want to display only print and no part of body.

neha
+1  A: 

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.

digitalFresh