...

View Full Version : trying to prevent table from printing part on two pages



bazz
10-28-2009, 05:49 PM
Hi,

I am outputting a page which has four tables on it. looks fine in the browser and I am now doing the print css.

How can I force a table to print on one page rather than starting on one and finishing on the next?


I have tried the

page-break_inside:avoid

but it seems not to work.



#bookings_details_panel table {
width : 100%;
margin-top:10px;
border:0;
page-break-inside:avoid;
}


bazz

Rowsdower!
10-28-2009, 06:00 PM
Looks like it's only supported in Opera...

bazz
10-28-2009, 06:16 PM
Thanks Rowsdower; well spotted. I had seen that the prooerty is supported by all major browsers but hadn't seen that 'avoid' was only supported by Opera.

OK, so is there any way to be sure that if a tbale were to be straddling two pages, that it is to be printed on just one? without js?

bazz

Rowsdower!
10-28-2009, 06:30 PM
Well, the "avoid" is not the Opera-only part (as far as I know) - it's the entire page-break-inside style. All major browsers support page-break-before and page-break-after (and support the avoid property for it, too). It's a shame, really, as this would be a very convenient feature.

Anyway, I've never seen any HTML/CSS solution for this exact problem so you probably would have to resort to scripting (perhaps even a server-side addition of a no_break class or something when the table has more than "x" <tr>s in it) or else purposely breaking the page before each and every table using page-break-before. Obviously you can get creative with work-arounds, but for any sort of native and natural support for what you're after I think you're sunk. :(

I take back the part about all browsers supporting "avoid" as it appears as though FF, Chrome, and Safari DO NOT support it. Still, nobody but Opera supports page-break-inside. I have read that page-break-inside:avoid; is part of the default behavior for CSS2 though but I'm not sure if that's accurate at all.

bazz
10-28-2009, 08:39 PM
Thanks.

I have ensured that my first two tables are of a standardised height. They have a maximum number of rows to output and if in some cases, fewer will be outputted, I have made the script output empty rows, with a simliar height as when populated so that the table will be of the same height regardless of its content.

So, provided they page to be printed on is A4; it works fine for FF and IE6. Got to check IE7 and 8 before I can consider it reasonably proficient.

bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum