Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a div content to print in the center of a 8.5x11 sheet of paper?

Tags:

html

css

printing

I echo out information into a div and I have a jQuery print element to print that div. But the paper is always printed off-center. How can I manage to design the div to print in the center of the page? is there an exact height/width to follow?

This is my div css class

.contract {
   align: 0 auto;
   text-align: center;  
   width: 800px;
   background-color: #fff;
   clear: both;
   display: block;
}
like image 1000
Jaylen Avatar asked Mar 23 '13 17:03

Jaylen


1 Answers

Use this CSS

@media print {
    #printDiv{
         position:absolute;
         width:300px;
         height:300px;
         z-index:15;
         top:50%;
         left:50%;
         margin:-150px 0 0 -150px;
    }
}

Value of Margin should be 50% of the width and height value

like image 133
Vignesh Sakthivel Avatar answered Nov 13 '22 15:11

Vignesh Sakthivel