The header will only show once and not repeat on subsequent pages when it becomes lengthy

After implementing the solution found at this Stack Overflow post, I was able to display the header on every page. However, when the height of the header increases, it no longer repeats as expected!

I'm wondering if there is a specific limitation on how many times the thead can be repeated? And if there is, how can I adjust or increase that limit?

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
  <title></title>
  <script type="text/javascript">
    function PrintPage() {
      document.getElementById('print').style.display = 'none';
      window.resizeTo(960, 600);
      document.URL = "";
      window.location.href = "";
      window.print();
    }
  </script>
  <style type="text/css" media="print">
    @page {
      size: auto;
      /* auto is the initial value */
      margin: 2mm 4mm 0mm 0mm;
      /* this affects the margin in the printer settings */
    }
    
    thead {
      display: table-header-group;
    }
    
    tfoot {
      display: table-footer-group;
    }
  </style>
  <style type="text/css" media="screen">
    thead {
      display: block;
    }
    
    tfoot {
      display: block;
    }
  </style>
</head>

<body>
  <form id="form1" runat="server">
    <div>
      <table style="width: 500px; margin: 0 auto;">
        <thead>
          <tr>
            <td>
              <p>header comes here for each page</p>
            </td>
          </tr>
        </thead>
        <tbody>
             <tr><td>1</td></tr>
             <tr><td>2</td></tr>
             <tr><td>3</td></tr>
             <tr><td>4</td></tr>
             <tr><td>5</td></tr>
        </tbody>
        <tfoot>
          <tr>
            <td>
              footer comes here for each page
            </td>
          </tr>
        </tfoot>
      </table>
    </div>
    <br clear="all" />
    <input type="button" id="print" name="print" value="Print" onclick="javascript:PrintPage();" class="button" />
  </form>
</body>

</html>

Answer №1

When constructing tables in HTML, remember to use the <th/> tag within the thead section instead of the <td/> tag.

<!DOCTYPE html>
<html>
  <head>
    <style>
      table,
      th,
      td {
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <h1>The thead, tbody, and tfoot elements</h1>

    <table>
      <thead>
        <tr>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th>
            <p></p>
            <p>header comes here for each page</p>
            <p />
          </th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
          <th><p>header comes here for each page</p></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>January</td>
          <td>$100</td>
        </tr>
        <tr>
          <td>February</td>
          <td>$80</td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td>Sum</td>
          <td>$180</td>
        </tr>
      </tfoot>
    </table>
  </body>
</html>

Answer №2

The key to success is to utilize the th element in the table header:

 @page {
      size: auto;
      /* The 'auto' value is used by default */
      margin: 2mm 4mm 0mm 0mm;
    }
<form id="form1" runat="server">
    <div>
      <table style="width: 500px; margin: 0 auto;">
        <thead>
          <tr>
            <th>
             Table heading
            </th>
          </tr>
        </thead>
        <tbody>
             <tr><td>1</td></tr>
             <tr><td>2</td></tr>
             <tr><td>3</td></tr>
             <tr><td>4</td></tr>
             <tr><td>5</td></tr>
              ...
             <tr><td>55</td></tr>
        </tbody>
        <tfoot>
          <tr>
            <td>
              Footer content goes here for each page
            </td>
          </tr>
        </tfoot>
      </table>
    </div>

  </form>

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

Mirror the image horizontally prior to saving

I'm working on a camera web app that has filters similar to Snapchat. I'm currently facing an issue where the image is mirrored because I'm using the front camera. Is there a way to flip the image before downloading it? Thank you for your re ...

The skipping of crucial text in tab focus is adversely affecting the accessibility of the website

My appbar contains an image link, a warning indicating the user's current environment, and details about the logged-in user. While testing accessibility with a screen reader, I noticed that tab focus skips over the user details in favor of a link in ...

The alignment of the images is off, with varying heights that do not match

My current issue involves images appearing in varying heights and the text underneath not aligning properly. Here is the markup: I have six row containers to showcase 6 different images. <div class="row"> <div class="posts"> <im ...

Working with files in JavaScript

Has anyone ever tried to create an HTML file in the same directory using JavaScript? I did some research on Google and came across using ActiveXObject like this: var fso = new ActiveXObject("Scripting.FileSystemObject"); var FileObject = fso.OpenTextFile( ...

Transforming a Bootstrap 4 HTML project into Angular 9

After stumbling upon a beautiful HTML template that caught my eye, I realized it was built using Bootstrap. Luckily, I came across tutorials on how to convert such templates into Angular 6 projects, making the process seem quite straightforward (like this ...

Start your slideshow automatically (with an option to toggle)

http://jsfiddle.net/r6uf38v4/ After the page loads, my goal is to have the slider begin automatically. However, I also want to provide the option for users to pause it using a checkbox and then resume the slider. $('#checkbox').change(function( ...

The constant motion of jQuery images is mesmerizing

Having trouble with a slide effect in my project. I have set up 4 images, where images 3 and 4 should slide down when clicked. Additionally, a div element should come down from them. I'm new to this, so apologies if it's a simple question. Any as ...

What are some ways to restrict dynamic form submissions?

$(document).ready(function(){ var i = 1; $('#add').click(function(){ if(i < 5){ i++; $('#dynamic_field').append('<tr id="row'+i+'"><td><div class="form-group">& ...

Preventing the ScrollTop Function from Triggering in Jquery Upon Link Click

Hey there! I'm currently facing an issue with jquery scrollTop. Whenever I navigate to the id #linkA and click it again, an unnecessary scroll is added. I'd like to prevent scrolling after clicking the link. Imagine these three paragraphs have a ...

Is the presence of a 'disabled' attribute on a non-input element enough to render your document invalid in HTML?

Originally intended for <input/> elements, the disabled attribute raises a question when applied to non-input elements. Could this potentially lead to document invalidation? ...

What is the best way to showcase a bootstrap card in a horizontal layout using Jinja 2 and a for loop

I'm facing a challenge in showing bootstrap cards in a horizontal layout instead of the default vertical arrangement using a for each loop. Below is the code snippet: <div class="row"> <div class="col-lg-12"> {% for game i ...

What causes background images to be affected by collapsing margins?

I am working with simple HTML and CSS code. One issue I have noticed is the bottom margin collapse between the .outside box and the .inside box. I am puzzled as to why the background image does not show when this bottom margin collapses, as the backgroun ...

What are some creative ways to format text displayed using ngx-markdown?

I'm currently in the process of building a blog using Angular and I have decided to use Markdown for creating my posts. Specifically, I am looking into integrating ngx-markdown for rendering purposes. As of now, I am developing a component dedicated t ...

The CSS file stubbornly refuses to connect, opting instead to redirect back to the HTML file

Something strange has occurred. I was working on a React app and everything was functioning properly until today when I returned to it, and my CSS file wasn't linking for some reason. The only actions I took were running npm run build and npm run depl ...

Extract information from a JSON file to populate a jQuery Datatable

I am attempting to include data from a JSON file that was created using a Django script. Here is the structure of the JSON file: [ { "6": "yo1", "1": "2019-04-04", "4": "yo1", "3": "yo1", "2": "yo1", "5": "yo1" }, { "6": "yo2" ...

What is the best way to include multiple selected option values from select2 in form.serialize()?

I am trying to use select2 for selecting multiple options in HTML and then send the selected values as an array using form.serialize() to update a database field. However, my form also contains other input fields. How can I achieve this? Here is my HTML c ...

I'm experiencing an issue where the video from my server is not being displayed within the <video> tag in the browser, but when using the web URL, the video plays

When it comes to uploading a video, there are two options available: 1) Provide the web URL for the video, 2) Upload the actual video file. The <video> tag works smoothly with a web URL as the source, but issues may arise when trying to play an uplo ...

Transitioning Menus with Submenu Animation

After following a CSS menu tutorial and customizing it, two issues have arisen. When hovering over the "About" menu with additional list links, the transition works but then the content shifts to the left and fades out. The second issue is related to tryin ...

Active positioning within a parent div

I'm having difficulty getting a color picker JavaScript widget to function properly within a webpage that contains unchangeable elements. Some of these elements are causing the color picker to be displayed far below the link once clicked. Here is a si ...

"Creating dynamic web apps with the powerful duo of Meteor and Zurb

Just starting out with programming and currently working on a new web application using Meteor and AngularJS. I would like to incorporate the elements/css from 'Zurb Foundation For Apps' into my project... I am familiar with including Bootstrap ...