Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid table border split on page break while printing

Tags:

html

css

printing

My content is already on the same page, that's not what the problem is. (Some other questions on SO tackle that). My issue is with borders specificaly. See how the table border splits row 43 in two.

enter image description here

I would like 43 to be on the next page completely. 42 should have a bottom border and 43 should have a top border. Here is what I want. (I created this in paint)

enter image description here

I tried page break inside: avoid but that doesn't work. Neither does the 4px trick works. I am in latest stable chrome. 51

like image 268
Achshar Avatar asked Jul 04 '16 20:07

Achshar


People also ask

How do I prevent page breaks in a table?

Similarly, you can avoid page breaks inside tables, lists, and any other block-level element. A code block split into two spanning across two pages because of a page break inside it. This can be avoided using the page-break-inside property.

How do I keep HTML tables from splitting across pages?

Select the table which breaks across two pages, and then click Layout (under Table Tools) > Properties. See screenshot: 2. In the popping out Table Properties dialog box, (1) enable the Row tab, (2) uncheck the Allow row to break across pages option, and (3) click the OK button.

How do I prevent a page-break in a div?

Syntax: page-break-inside: auto; avoid: It avoids a page break inside the element.

How do I make a page-break dynamic in HTML?

page-break-before: auto instead of . page-break-before: always. The "auto" will break the page only if the contents are at the end if the page, this will prevent breaking the page and leaving a lot of blank space. Show activity on this post.


1 Answers

Could you please try this css code:

<html>
<head>
<style>
@media print
{
  table { page-break-after:auto }
  tr    { page-break-inside:avoid; page-break-after:auto }
  td    { page-break-inside:avoid; page-break-after:auto }
  thead { display:table-header-group }
  tfoot { display:table-footer-group }
}
</style>
</head>

<body>
....
</body>
</html>
like image 108
vignesh Avatar answered Sep 28 '22 11:09

vignesh