What is the optimal height for a header that will allow for a repeating header on each printed page of a website?

I have encountered an issue with my report while using the print option in Chrome. I need to ensure that my headers are repeated on each page.

To structure my content properly, I have divided it as shown below and it is currently functioning correctly:

<table>
    <thead>
        <!-- Header Content (needs to repeat) -->
    </thead>
    <tbody>
        <!-- Body Content -->
    </tbody>
</table>

However, this method only works up to a certain height of the header. If the header exceeds a certain height, the repeating function stops working.

I noticed that changing the paper size from standard A4 to a larger size, like A3, allows the repeating header to work for the taller header. Conversely, if the repeating header is functional on A4 paper but the paper size is reduced to A5, the functionality is lost.

I am unable to determine the exact height at which the issue occurs, but it has affected both my live project and sample tests.

Please take a look at the samples provided and let me know if there is something missing or if any adjustments need to be made.

https://i.sstatic.net/e9xGu.png https://i.sstatic.net/fUrBU.png https://i.sstatic.net/BKYYo.png https://i.sstatic.net/wVnnu.png

Answer №1

The limit is set at 245px in Chrome, but depending on the content, it might need to be reduced. We've seen good results by keeping it under 230px.

If you require more space, one workaround is splitting the content into two sections, each limited to 230px. The trick is to stack multiple table headers together to create the illusion of a single large header. Nest a second table within the tbody. It's not a perfect solution, but it gets the job done. Hopefully, this advice proves helpful.

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="example.css" />
</head>
<body>
    <table class="w-100">
        <thead>
            <tr>
                <td>
                    <!--placeholder for the fixed-position header-->
                    <div class="header1">
                        <h1>Header #1</h1>
                    </div>
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <table class="w-100">
                        <thead>
                            <tr>
                                <td>
                                    <div>
                                        <div class="header2">
                                         <h1>Header #2</h1>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                <p>Lorem ipsum dolor sit amet... [content continues]
                                </p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>
                    <!--placeholder for the fixed-position footer-->
                    <div class="page-footer-space"></div>
                </td>
            </tr>
        </tfoot>
    </table>
    <div class="footer w-100">
        <h2>footer</h2>
    </div>
</body>

</html>

CSS:

.header1, .page-header-space {
    height: 230px!important;
    overflow:hidden;
}

.footer, .page-footer-space {
    height: 230px;
}

.header1{
    background-color: rgba(223, 223, 223, 0.5);
}

.header2{
    background-color: rgba(223, 223, 223, 0.5);
    height:230px;
}

.footer{
    background-color: rgba(223, 223, 223, 0.5);
}

@media print{
    .page-header, .page-header-space {
        height: 230px!important;
        overflow:hidden;
    }

    .footer {
        position: fixed;
        bottom: 1px;
    }
    thead {display: table-header-group;}
    tfoot {display: table-footer-group;}
    body {margin: 0;}
}


.w-100{width:100%;}



/*---Reset---*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    border-spacing:0;
}

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

Waypoints script behaving unexpectedly

I am currently developing a website with a one-page scroll layout. To achieve this, I am utilizing the jquery.onepage-scroll.js library for the layout. My goal is to incorporate animations as users scroll through different sections of the page. I attempted ...

The sticky navigation bar hack (implementing fixed positioning with jQuery)

Essentially, when the navigation bar (or any other element) reaches the top of the page or window, a class called "sticky" is added to the element and CSS styles it as fixed. This functionality acts like an IF statement - if the element is far from the top ...

What could be causing the malfunction of slideToggle in this situation?

I have been troubleshooting this issue all night and I am completely stuck. Can anyone figure out why the navigation menu is not opening? Here is the HTML code: <ul id="nav"> <li><a href="item1.html">item1</a></li> & ...

Is it possible to perform a CSS flip animation without delay?

Trying to implement David Walsh's CSS flip effect for an image that should change to another without requiring a mouseover. Is there a way to trigger it automatically, maybe in 3 seconds? I'm new to this so any help would be greatly appreciated! ...

"Encountering issues with hyperlink tags in app engine - they are not functioning

Currently facing an unusual issue. I created a simple website and all I want to do is navigate from one page to another. It works perfectly fine locally, but when I deploy it on Google's App Engine, my links only take me back to the index page. Can&ap ...

Customizing Background Color in React Bootstrap Table Based on Value

Having a little issue that's causing me some trouble. I have a React Bootstrap Table displaying data from an API, and I'm looking to enhance it by changing the row color to green if a specific value is greater than zero. Here is an example: const ...

The problem of duplicate ids: Once an id is used, it cannot be

Currently, I'm focusing on a specific script : http://www.andwecode.com/playground-demo/pop-up-login-signup-box-jquery/# I've made some adjustments to the Gmail and Facebook boxes within this script. When clicking on them, I want them to displa ...

Does Xamarin.Forms have a feature similar to html datalist that enables the selection of predefined values while also allowing for the input of free text?

We are currently developing a Xamarin forms application. One of the necessary features is a selection field where users can either choose from predefined options or enter their own text value, similar to using a text field. In HTML, this could be easily ...

What is the best way to incorporate Tradingview's JavaScript into the render function of a React Typescript

I'm trying to incorporate some widgets into my Typescript React component. Here is the embed code export default class App extends React.Component { render(): ReactNode { return ( <div> Chart test <div className= ...

Tips for loading HTML content before executing any JavaScript code or requesting user input via prompt

I am looking to have the page function in a specific way: The HTML loads, and the first prompt asks the user for input. Once the prompt is submitted, the running total changes and is displayed on the page. The same process happens for the second prompt and ...

Struggling with jQuery not updating class attributes for list items, any solutions to resolve this issue?

In order to have a unified navigator for various classes, I have stored it in a separate HTML file and am attempting to import it into the home page using jQuery. <!-- ======= Header ======= --><!-- End Header --> <div id="header-par ...

Enhancing User Experience with CSS

Is there a way to create a link within a div and change the hover color to indicate it's a link? The challenge is that my div contains both an image and text in separate divs. div { :hover { background-color: light cyan; } Currently, when I hov ...

Refreshing the page to fetch dynamically updated content

I've been working on a search feature reminiscent of Google Instant using jQuery. Everything seems to be working well, but I've encountered an issue. Whenever the page is reloaded, or if a user navigates away and comes back, the search results di ...

The headers in the div section are not properly aligned on the webpage

My current project's website has a homepage with two rows of content. Each row consists of 2 paragraphs, each with a heading and corresponding buttons. However, the issue is that I want the headers in each row to align with one another so that the fir ...

Transform CSS into JavaFx CSS

Currently, I am working on migrating a web application to JavaFX and need to style it in the same way as the original CSS. However, when attempting to load the CSS from the web project into JavaFX, I realized that the styles were not being reflected. Upon ...

Pinpointing a specific region within an image by utilizing offsets

Would it be possible to detect a specific area within an image using a predefined set of image offsets? Here is the image and accompanying offsets: Sample Image Below are the sample image offsets for the highlighted area: Offset(63.4, 195.2) Offset(97.7 ...

What is the best way to play a random song when the user clicks a button?

My goal is to develop a website where users can click on an image and have a random song play from a playlist. I currently have a functioning code that activates one song, but it fails when adding multiple songs to the mix. <html> <head> ...

Designing a scrollbar for a tr element using HTML and CSS

I am struggling to create a scrollbar for the inner table that is not being displayed within its container. The container has a yellow background while the table itself is blue. My goal is to have a scroll bar specifically within the table. For more info ...

How to reduce the default width of Bootstrap carousel components

Click here for the 1st image. To view the 2nd image, click here. This represents the carousel code used on this particular website: <div class="row testing"> <div id="carouselExampleMen" class="carousel carousel-dark s ...

Anticipated scenarios when using selenium

How can I verify the presence of a br tag in HTML using expected conditions? Below is the snippet of HTML code: <br> <a href="member.php?u=12455" rel="nofollow">Smatta</a> <a>, </a> <a href="member.php?u=14305" rel="nofoll ...