What is the best method to ensure a TALL table header is repeated on every page in Chrome?

First time poster =)

I am currently facing an issue while trying to print a long table and have the table header repeat on each page. The problem arises when the height of the <thead> reaches a certain threshold, specifically 242px in Chrome 87.0.4280.88 with default margins. When the header exceeds this height, it only prints once on the first page. Adjusting the page margins does provide some flexibility, but I am looking for a workaround that would allow me to print a taller <thead> on every page without modifying the margins. I have searched for documentation regarding this issue but have not found a solution yet, so any help would be greatly appreciated.

<table>
  <thead>
    <th style='height: 242px'>if this was 241px it would print on every page</th>
  </thead>
  <tbody>
    <tr><td>anything</td></tr> <!-- repeat this process enough times to span multiple pages -->
  </tbody>
</table>

Thanks in advance!

Answer №1

To achieve this effect using only CSS, you can apply the following styles to target your table:

<style>
  thead {
    position: fixed;
    top: 0;
  }

  thead th {
    height: 380px;
  }

  tbody tr:nth-child(25n + 1) td {
    padding-top: 380px;
  }

  tbody tr:nth-child(25n + 26) {
    page-break-before: always;
    break-before: always;
  }
</style>

This CSS code fixes the position of thead so it shows on every page, adds a top padding equal to the height of thead to every 25th td in tbody, and includes a break-before property for every 25th tr except the initial one.

You can modify the nth-child selectors to match the height of your content rows accurately for proper page breaks.

Answer №2

The issue may be originating from the browser and how it interprets your website. One possible solution could involve creating multiple identical headers and using a different one on each page, even if they appear identical.

<table>
    <thead>
        <tr><th style='height: 242px'>Header 1</th></tr>
        <tr><th style='height: 242px'>Header 2</th></tr>
    </thead>
    <tbody>
        <tr><td>anything</td></tr>
    </tbody>
</table>

Another option, involving the use of php, would be to create an include where you generate a single header.html file and call it on every page. If you are interested in exploring this alternative, feel free to request more details, and I can provide an example for you.

Answer №3

 <table id="header-table">
  <thead>
    <th style='height: 242px'>Tall header</th>
  </thead>
</table>

<table id="main-table">
  <tbody>
    <tr><td>anything</td></tr> <!do this as many times as you want -->
  </tbody>
</table>

Utilizing the method above, you have the option to separate the header, and for a repetitive process, consider incorporating JavaScript libraries like jsPDF or printJS along with CSS styling in the file.

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

JavaScript - Utilizing an image file in relation to a URL pathway

Is there a way to reference an image URL using a relative path in a JavaScript file similar to CSS files? To test this, I created two divs and displayed a gif in the background using CSS in one and using JavaScript in the other: -My file directory struct ...

Adjust the parent element to match the width of the child by utilizing the "display: grid" property

edit: I'm uncertain if this is a duplicate issue. My concern is not about the background color extending beyond the container width, but rather about expanding the container to match the size of its child with display: grid. I have updated the example ...

Switch to display only when selected

When I click on the details link, it will show all information. However, what I actually want is for it to toggle only the specific detail that I clicked on. Check out this example fiddle Here is the JavaScript code: $('.listt ul').hide(); $( ...

Media query failing to adjust properly

On my website's "about" page, I'm attempting to implement a media query but encountering an issue. In the original CSS, I structured the "information" section into 2 columns with right padding to prevent the content from extending all the way to ...

What is the best way to assign a unique ID to every element in this situation?

Here is the given code: var words = ['ac', 'bd', 'bf', 'uy', 'ca']; document.getElementById("wordTable").innerHTML = arr2tbl(2); function arr2tbl(ncols) { return words.reduce((a, c, i) => { ...

What is the best way to make a Dojo TitlePane overlap using CSS?

My dilemma involves a jsfiddle featuring two TitlePane widgets in the central pane's top right corner. Currently, clicking on the right TitlePane ("Switch Basemap") moves the left TitlePane ("Map Overlays") to the left. What I want is for the right Ti ...

Looking to switch up the thumbs-up button design?

I am a beginner in using jquery and ajax, and I need some assistance. How can I incorporate this jquery code into my logic: $('.btn-likes').on('click', function() { $(this).toggleClass('liked'); }); Can so ...

Struggling to align block elements correctly after changing them to inline

I've been trying to align this paragraph while keeping the navigation menu and logo in their correct positions. I attempted to make everything inline, but that didn't work. Then I experimented with the float property, which only made things worse ...

Change the color of the image to black and white and then back to its original state when a specific element is hovered over

Searching for a jQuery plugin to convert an image to black and white? Look no further! I've explored various options, but none quite fit the bill. What I'm really after is an effect that will revert the image back to color when a specific element ...

Using Jquery to Bind Multiple Events

As a novice in jquery, I have been trying to develop a search function that functions properly without any issues, until I introduced the select element. Can you please help me identify where I might be going wrong? $(function () { $('#keresomezo&apo ...

What is the best way to integrate HTML templates into AngularJS?

I am currently working on developing an HTML fragment that will eventually function as an image slider. At this point, it only consists of a test div element: slider.html: <div>TEST</div> In order to incorporate this into my index.html, I hav ...

Guide on forwarding from one HTML page to another in the local disk

Currently, I am working on an employee appraisal application where users can submit appraisals that are stored in the backend. The initial page is a login screen. Once the user successfully logs in, they should be redirected to another page displaying in ...

A guide on showcasing items on an html webpage through the use of javascript

Currently, I have a series of hardcoded HTML elements in my code snippet. <!-- Reciever Message--> <div class="media w-50 ml-auto mb-3"> <div class="media-body"> ...

Is there a Joomla extension available that can display or conceal content upon clicking?

Looking to enhance my Joomla site by installing a plugin that allows me to toggle the visibility of content with a click, similar to how FAQ sections work on many websites. Question 1 (click here for the answer) { Details for question 1 go here } Questi ...

JSON syntax error: "r" is not a valid token at the beginning position

Currently, I am in the process of developing a web server that is based on STM32 MCU. The workflow involves the browser sending a request to the MCU, which responds with a web HTML file. Users can then adjust parameters and use a form to submit them back t ...

Deciphering HTML encoding for text fields

As I transition from the Microsoft stack, specifically WPF, to HTML5, I apologize for any beginner-level questions. Today's topic is HTML encoding and decoding. Imagine an HTML5 application making AJAX calls to a C# backend using HTTP. The server al ...

Bootstrap's ability to display panels of equal height across multiple rows is a game

Just started using Bootstrap 4 after being familiar with Foundation for years. In Foundation, equalizer was a tool to ensure divs had the same height, which would be applied to all divs within a container. I understand that Bootstrap uses Flex, but I&apos ...

Tips for updating the date format in Material UI components and input fields

Is there a way to customize the date format in Material UI for input text fields? I am struggling to format a textField with type 'date' to display as 'DD/MM/YYYY'. The available options for formatting seem limited. It would be helpful ...

Another element concealing an element underneath

I am currently working on a website and could really use some assistance. Being new to web design, I find myself puzzled by this particular issue. The problem I'm facing is with a sawtooth pattern that should be displayed over a header, similar to the ...

Tips for handling numerous buttons in ionic?

I'm currently working on an app that includes surveys. In this app, users are required to answer by selecting either the Yes or No button. The desired behavior is for the chosen button to turn blue once clicked, while the other button should maintain ...