Solved

HTML page breaks

Posted on 2004-09-29
7
917 Views
Last Modified: 2008-03-17
Is there a way to put something like page breaks into a table in HTML so that when the user prints the page, rows are not split between 2 pages?  I am not at all familiar with JavaScript but am willing to learn it if necessary.
0
Comment
Question by:LBugbee
7 Comments
 
LVL 5

Expert Comment

by:php-webdesign
ID: 12178948
0
 
LVL 1

Accepted Solution

by:
bame earned 250 total points
ID: 12180143
Instead of telling the browser where to break, you can tell the browser NOT to put page breaks in rows by setting the "page-break-inside" CSS property to "avoid".

<table>
<tr style="page-break-inside: avoid">
<td>...</td>
</tr>
</table>

If you really do want to force page breaks, take a look at page-break-after and page-break-before.

For details: http://www.w3schools.com/css/css_ref_print.asp

Note: Mozilla-based browsers (like Netscape) don't support this yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=132035
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12182414
If you are printing a table, it is very like to get screwed up will some setting no matter what you do.  If there are nested tables then the chances of success are somewhere a little less than zero.  If the printing is critical, then use a pdf or other print friend file type; or develop a printer friendly stylesheet that does a rendering without the tables.

Cd&
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:minichicken
ID: 12182448
This is what I use to do page breaks for printing pages
use style="page-break-before:always" in your table tag

Example:

<table style="page-break-before:always" width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>

j311y :)
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12184320
As to what minichicken says, better assign that style to your tr's because ;-)

<style type="text/css">
 table.unbreakablerows tr {page-break-before:always;}
</style>

<table class="unbreakablerows">
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
<tr><td>Data<br/>Data<br/>Data<br/>Data<br/>Data<br/>Data</td></tr>
</table>

-r-
0
 

Author Comment

by:LBugbee
ID: 12184608
Bame's suggested "page-break-inside: avoid" sounds like what I'm looking for but it didn't work. (IE6) I don't want a new page everytime I start this row, only if it's going to overflow to the next page.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12184752
Use page-break-inside:avoid;

or page-break-before:auto;

See also: http://www.w3schools.com/css/css_ref_print.asp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now