1

I create a web page with table rows. It is looking good when i press print button. But sometimes page breaks are cutting page middle of the block. I tried to use tbody as this

<table>
...
<tbody>
<tr><td>sample datea 1</td></tr>
<tr><td>sample datea 2</td></tr>
<tr><td>sample datea 3</td></tr>
</tbody>
<tbody>...</tbody>
...
</table>

When i want to print page it writes as

//first page  
sample datea 1 
sample datea 2 
// second page
sample datea 3 

I want to cut after sample datea 3 . I tried to add blokla's div tag CSS as

.blokla{display:block;page-break-inside:avoid; page-break-after:auto}

How can i break page between div tags or another ? My main problem is below.

enter image description here

enderaric
  • 142
  • 4
  • 15
  • 1
    can you create a demo? – G.L.P Apr 27 '15 at 12:24
  • 1
    see [Using CSS and/or jQuery for Printed Pages with Page Breaks](http://stackoverflow.com/questions/4878013/using-css-and-or-jquery-for-printed-pages-with-page-breaks) for your answer – sachin.ph Apr 27 '15 at 12:29

2 Answers2

1

The CSS you have is valid and works on my end.

However the problem you have is that you are creating two <tbody> tags in a single table. This practice is not "valid" HTML (it is valid). Use only one <tbody> and use this CSS;

tr{page-break-inside:avoid; page-break-after:auto}

Changing the CSS in this way ensures for maximum flexibility in your HTML, presentation for each row will now remain together.

glend
  • 1,592
  • 1
  • 17
  • 36
0

I solved this question with this code

tbody{page-break-inside:avoid; page-break-after:auto; position:relative;
display:block;}

It is working fine.

enderaric
  • 142
  • 4
  • 15
  • You can get rid of the `page-break-after:auto;` and `position:relative;`. Also, this solution will only work if: a) all of the data in each column is exactly the same width, or b) you set widths on the `td` elements in each `tbody`, and don't add any content that exceeds those widths. – DoctorDestructo Apr 29 '15 at 23:50