How to deal with page breaks when printing a large HTML table

前端 未结 12 2059
有刺的猬
有刺的猬 2020-11-22 16:44

I have a project which requires printing an HTML table with many rows.

My problem is the way the table is printed over multiple page. It will sometimes cut a row in

12条回答
  •  天命终不由人
    2020-11-22 17:22

    The accepted answer did not work for me in all browsers, but following css did work for me:

    tr    
    { 
      display: table-row-group;
      page-break-inside:avoid; 
      page-break-after:auto;
    }
    

    The html structure was:

    
        ...
      

    In my case, there were some additional issues with the thead tr, but this resolved the original issue of keeping the table rows from breaking.

    Because of the header issues, I ultimately ended up with:

    #theTable td *
    {
      page-break-inside:avoid;
    }
    

    This didn't prevent rows from breaking; just each cell's content.

提交回复
热议问题