Row in the table exceeds page limit (print publication)

When I print my table (ctrl+p), it does not break the way I want. The last row of the first page splits with part on the second page. Is there a solution for this issue? The rows can vary in content and size, and I have tried using properties like

page-break-before/after: auto. page-break-inside:avoid;
but to no avail. Any suggestions on how to break and move the table parts to the next page without splitting the last row for print media would be greatly appreciated.

table,th,td { border:1px solid black; border-collapse:collapse; } th,td { padding:5px; }

</style>
</head>
<body>
<table style="width:100%;">
<tr>
  <th><span>Firstname</span></th>
  <th><span>Lastname</span></th>      
  <th><span>Points</span></th>
</tr>
<tr>
  <td><span>Jill</span></td>
  <td><span>Smith</span></td>     
  <td><span>50</span></td>
</tr>
<tr>
  <td><span>Eve</span></td>
  <td><span>Jackson</span></td>       
  <td><span>94</span></td>
</tr>
<tr>
  <td><span>John</span></td>
  <td><span>Doe</span></td>       
  <td><span>80</span></td>
</tr>
   /* Numerous other <tr> elements here */
</table>

</body>
</html>

Answer №1

To achieve the desired outcome of your table only breaking between rows and not within them, you can utilize a CSS rule in Firefox and Internet Explorer like so:

tr {page-break-inside: avoid;}

However, please note that this method may not be effective in other browsers such as Chrome.

Another approach is to prevent page breaks within the content of individual cells by enclosing them in a div with "page-break-inside: avoid;" applied. Keep in mind that if the height of the content varies within the row, parts of it may still end up on different pages.

If you are determined to address this issue and are open to using some JavaScript, I have shared a solution here that should provide the desired result.

Answer №2

If you want to create a page break that is hidden on the screen but will appear when you print, there are some rules you should be aware of. The CSS property page-break-before:always can only be used on block elements, not inline or table-row elements. This means you can't apply it directly to a row or cell, and adding an empty div with this style won't work either. You may need to wrap the content in a <div> or <p> tag to achieve the desired effect.

Similarly, page-break-after:always can be used at the end of a previous element to force a page break. However, this can be frustrating if you're trying to protect a specific grouping or row.

Some browsers might require you to set the table style to page-break-inside:auto, as tables often have a default style of page-break-before:avoid. Keep in mind that adding this style won't necessarily help, as the browser is already doing its best to avoid breaking up your table.

In Chrome particularly, failing to remove the default style can render other options useless. It's important to understand how these rules work to achieve the desired page breaks in your printed document.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize JasperReports in conjunction with Spring MVC to effortlessly generate and print reports on the client side without the need

I am currently working on a project using Spring MVC with AngularJS. When it comes to printing reports, I have decided to use JasperReport for this purpose. Before proceeding further, I am curious to know if it is possible to generate a report and directl ...

Adding a <span> element within an <h1> tag in WordPress

I am attempting to create this layout in Wordpress using the code <h1>This is my <span>title</span></h1>, but I am unsure how to incorporate a <span> tag within the <?php the_title(); ?> function. After consulting the c ...

The flex reverse-column child's text selection occurred in the incorrect direction

I am having an issue with selecting text in a flex container that is set to reverse column. The selection I make is incorrect because the browser tries to select from the end of the element, resulting in improper selection. For example, <div style=" ...

Include the entire HTML script within a PHP file

Apologies in advance for this beginner question, but I need to get it right. I have created a website with all HTML files that are functioning properly. Now, for session handling, I need to convert all the HTML files to PHP code like below: <!DOCTYPE H ...

Customize TYPO3 templates by modifying the div id structure

I have a template in TYPO3 that I want to use for multiple pages. Within this template, there is a specific DIV element. I am wondering if it's possible to change the ID of the DIV based on the page UID. This DIV is the only one that changes its cont ...

Float: right; is causing distortion to the appearance of Div elements

I would like to style this image and text so that they float to the right with some spacing around them. However, when using float: right;, they end up extending beyond the default resolution excessively. #pageMain { margin: 100px; } #aboutGame { f ...

Is there a way to incorporate CSS directly into HTML from a local .css file when setting up a C# project? Is it possible to achieve this using PreMailer.Net?

Currently, I am working on updating a email templating system to incorporate external .css files instead of having all styles coded inline. In my ASP.NET project, it seems that the most commonly used and comprehensive inliner is PreMailer.Net. However, I a ...

How to use an if statement in Django when a button is clicked

I am trying to implement a functionality on my website where the user can click a button, and every time it is clicked the value of i should increase by 1. Currently, the code I have doesn't seem to work as expected. # HTML file snippet <form met ...

To enhance the MUI v5 table row, simply apply a border when the mouse hovers

After working on creating a table with Material UI v5, I encountered an issue where I wanted to add a blue border to the table row when the mouse pointer hovered over it. I attempted several methods and did thorough research, but unfortunately, I was unab ...

Experiencing discrepancies in pixel height while conducting tests using Nightwatch

Let me start by sharing some details about my machine setup: Operating System: CentOS 7 Graphics Drivers: kmod-nvidia (dedicated GPU) I am currently testing a webpage using Nightwatch, and one of the requirements is to ensure that a background image&apo ...

Creating a Drop-down Menu Item using React Material UI

I am experiencing an issue with displaying a MenuItem in my Dialog2 within my React app. Despite setting the zIndex: 1900 to a higher value than the two dialogs, the MenuItem remains hidden behind the dialogs instead of appearing at the front. Please revi ...

Creating unique URLs for websites can be accomplished by following these steps:

I am in the process of developing a website where content in the main div within the body section can be replaced. However, I have realized that all content will end up on the same URL. Any suggestions on how to fix this? HTML/PHP(index.php): <htm ...

Hidden input fields do not get populated by Angular submit prior to submission

I am in the process of implementing a login feature in Angular that supports multiple providers. However, I have encountered an issue with submitting the form as the loginProvider value is not being sent to the server. Below is the structure of my form: &l ...

Guide on inserting a row into a table class without unique values using jQuery

I have gathered information on stackoverflow regarding how to use jQuery to add a row to a table. $('.myTable').find('tbody:last').append('WHATEVER CODE'); Although this method seems to be effective, I have come across the i ...

Having difficulty accessing the value of a table td element in HTML using a jQuery selector

When creating a table, I utilize ng-repeat to generate table rows. Whenever the dropdown changes, a function is triggered which applies certain conditions. Based on these conditions, an object is added to an array that is bound to a scope variable. Here i ...

Hover state not responsive on screens of varying sizes due to style inconsistencies

Here are the CSS styles I'm using: @media (min-width: 769px) and (max-width: 992px) { .box:hover{ background-color:#000000; } } @media screen and (min-width: 993px) { .box:hover{ background-color:#ffffff; ...

Is it possible to create vertical-floating elements using CSS?

Can anyone help with a solution to my problem illustrated in the image? I am dealing with a DIV element of fixed height that contains a List. I need this List to display as columns, each list item having a fixed width. If there are too many elements in th ...

Displaying dynamic HTML content in a Bootstrap modal using React JS is a great

I have been attempting to showcase an Unordered List within a Bootstrap Modal in React JS, with the list being dynamic. My current approach isn't yielding the desired results as the HTML elements are appearing as strings. var ModalHeader = React.cre ...

Cause the browser icon to flash in the taskbar when a notification is received

After creating a monitor page for our product services, I wanted users to easily check the status of different services on that page. Now I am looking for a way to make the browser icon on the taskbar blink whenever there is an alert and the browser is mi ...

In what way can I fill out my search fields using the criteria included in the URL?

In the process of developing an asp.net web application, I have implemented a code snippet to construct a section for search fields. This code builds URL parameters based on user input: <script type="text/javascript> $(document).ready(function(){ ...