April 3, 2012

Printing HTML page

Question by Java

I have a very long table in my webpage. When I print it, it looks that the last row of the table is in the one page ( only in the top of the page ). The rest of the page is blank. On the next page I have nest table. I do not know, why next table is not in the bottom of the last row of first page.

In HTML looks in following way:

<table align="left" cellspacing="0" cellpadding="0" border="1">
  <thead>
    <tr>....</tr>
  </thead>
  <tbody>
    <tr>...</tr>
  </tbody>
</table>

<table align="center" width="800" cellspacing="0" cellpadding="0" border="1" style="margin: 0 auto 0 auto; page-break-inside: avoid;">
  <tbody>
    <tr>
      <td align="left" width="200">xxx</td>
      <td align="right" width="200">xxx</td>
      <td align="right" width="200">xxx</td>
      <td align="right" width="200">x</td>
    </tr>
    <tr>
      <td align="left" width="200">
      <td align="right" width="200">
      <td align="right" width="200">
      <td align="right" width="200">
    </tr>
    <tr></tr>
</table>

CSS:

background-color: white;
border: 1px solid #000000;
border-collapse: collapse;
border-spacing: 0;
font-size: 10px;
vertical-align: middle;

Answer by Starx

You can control the style-sheet used for print separately using

@media print {
   ....
}

Since you table is breaking inside, you can disable that using

@media print {
   table {
       page-break-inside: avoid;
   }
}
June 9, 2010

Is it Possible to change the Default Margins of Browser through JavaScript?

Question by Govind KamalaPrakash Malviya

I want to change the default margins of Browser through JavaScript because I want to print the displayed document on page but the margins are different on different browser??? plz help me to change default margins of browser. if you have any solution tell me.

Answer by Jaroslav Záruba

I would recommend adding reset.css to your page, and probably to all of your pages/projects.
This way you should be able to eliminate all differencies in default style values amongst browsers.

EDIT: check out one of the most valuable threads at StackOverflow.com

Answer by Starx

use jquery

$(document).ready(function() {
       $("body").css("margin","0");
});

Using CSS

body { margin:0; }
...

Please fill the form - I will response as fast as I can!