What is the best way to ensure the footer is always positioned at the bottom of each page

Hey there, I'm having an issue with printing a large table on my HTML page. I want the footer to appear at the very bottom of every printed page, but so far I haven't found a perfect solution. I came across using tfoot, which prints the footer at the bottom of every page except the last one. Here are some examples:

[tfoot example-1][1]

[tfoot example-2][2]

Another solution I found was using position fixed, but it ended up covering the last row of the table. Examples are shown here:

[Position fixed example-1][3]

[Position fixed example-2][4]

Here is the CSS style I've been using:

       thead{
        display: table-header-group;
    }
    tfoot{
        display: table-footer-group;
    }
    tr,td{
        border: 1px solid;
        page-break-inside: avoid;
    }
    .footer{
        position: fixed;
    bottom: 0;
    text-align:center;
    width: 100%;
    padding-top: 10px;
        }
    @media print {
        tr {
            page-break-inside: avoid;
        }

}

If anyone has a solution to either of these problems or knows of a solution I haven't tried yet, I would greatly appreciate the help. [1]: https://i.sstatic.net/DWCZ2.png [2]: https://i.sstatic.net/mkQAb.png [3]: https://i.sstatic.net/vTpam.png [4]: https://i.sstatic.net/t0LQu.png

Answer №1

This is an example of a display flex CSS style.

<html>

  <head>
    <title>Example Title</title>
  </head>
  <style>
    .container {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

  </style>

  <body>
    <div class="container">
      <main>
        <h1>Content goes here.</h1>
      </main>
      <footer>This is the footer.</footer>
    </div>
  </body>

</html>

There are more resources available online. You can search for

how to make an HTML footer stay at the bottom
or visit this link for more information.

Answer №2

Additionally, there are break, break-before, and break-after attributes that build upon the page-break attributes for various elements such as images, code snippets, tables, and lists. Trying out break-after on the footer could potentially resolve the issue you're facing.

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

Android experiencing issues with dynamically loading Border XML

I am having trouble setting a border dynamically for a RelativeLayout. Oddly enough, when I manually add the border in the activity XML file, it displays perfectly. However, when I try to generate the border dynamically, it doesn't appear. border.xml ...

Aligning content in a div with proportional elements, maintaining left alignment of the elements

Trying my hand at creating an HTML template to display TV shows as cover artwork. The layout is flexible, showing up to five shows per row on larger screens and a minimum of two on smaller screens like smartphones. It's been a while since I've wo ...

What method can I use to ensure that the sidebar stays fixed at a particular div as the user continues to scroll down the

Is there a way to automatically fix the sidebar once the user scrolls down and hits the top of the .Section2? Currently, I have to manually enter a threshold number which can be problematic due to varying positions across browsers and systems. Fiddle htt ...

Issues with Vue enter transitions not functioning as expected

I am currently involved in a project where I need to implement enter and exit animations for some components. When a component enters the screen, it should come from the bottom, and when it leaves, it should go upwards. The intended functionality is that w ...

Removing a specific MySQL row using HTML in collaboration with Node.js

I've been working on a feature to allow users to delete specific rows from a table. Each row has a "Delete" link at the end, but when I click it, nothing happens. There are no errors displayed, and the console shows that 0 row(s) have been updated, ye ...

Rails: How come my personalized stylesheet isn't taking priority over the font family?

I have included the Skeleton boilerplate css in my application from this source. It can be found within the directory app/assets/stylesheets. app/assets/stylesheets ├── application.css ├── custom.scss ├── normalize.css └── skeleton ...

In an HTML document, you may encounter whitespace that is not present in JSFiddle

Upon running this HTML file in my browser, I noticed that there is an 18px gap at the top of the first div. It's strange because this issue only occurs when I run the HTML locally on my browser, but everything works fine on JSFiddle. I'm puzzled ...

Change the <base> element programmatically during server-side rendering

Searching for a way to obtain the base URL for an HTML page, so that relative URL requests from the browser utilize that base. If you are looking for answers, check out this link: Defining root of HTML in a folder within the site root folder When serving ...

Specify the location of the resize button (corner)

Scenario : At the bottom of the page, there is a resizable textarea, However, having the resize button at the bottom-right corner does not provide the best user experience (try it out), Issue : I am wondering if there is a way to move the resize butt ...

The JavaScript function document.getElementById.onclick is not functioning as expected

One issue I am facing involves counting all downloads on my website. My current approach is to increment a value in my database each time a download button is clicked, and then display this value. Despite trying multiple methods, the download count always ...

Set up an event listener for a specific class within the cells of a table

After spending the last couple of days immersed in various web development resources, I find myself stuck on a particular issue. As someone new to this field, the learning curve is quite steep... Let's take a look at a single row in my project: < ...

Incorporate personalized design elements within the popup component of Material-UI's DataGrid Toolbar

I am in the process of customizing a Data Grid Toolbar component by making adjustments to the existing Grid Toolbar components sourced from Material-UI. For reference, you can view the official example of the Grid Toolbar components here. Upon clicking o ...

Tips on how to pass properties as arguments to mixins

Here is the code I have: mox(first, second) {first} second a mox(transition, 0.3s linear all) I want to call the mixin like this: mox(transition 0.3s linear all) If we modify mox, it would look like this: mox() arguments a mox transition 0.3 ...

Using the PHP mail() function to send an email with an attachment

I have developed two scripts for this specific HTML code along with a corresponding PHP script. Below is the HTML markup: <html> <body> <form action="http://senindiaonline.in/admar/non-series-numbers-db.php" method="post" target="_bl ...

Favicon not displaying on the webpage

I am running a website and I want to add a favicon, but for some reason, it is not displaying correctly. When I view the site on my local server, it just shows a cloud symbol, and when I open the HTML file directly in a browser, it doesn't show any fa ...

Persistent button positioned at the bottom of the page, remaining visible even when scrolling to the very end of the content

I am looking to add a floating button that remains in the same position relative to the content until the window is scrolled to a certain point, after which it sticks to the end of the content. In simple terms, I want the element to act as 'relative& ...

How can I change the text of a single button by clicking on it without affecting the other buttons that share the same

Currently, I am implementing a posting system where posts can be added using a button. The posts have two additional buttons - one to show/hide content and the other to delete content. I am utilizing jQuery's slideToggle event to toggle the visibility ...

Boosted by Bootstrap 4 running smoothly on Internet Explorer version 10

I'm starting to have second thoughts about my decision to move to B4. I'm currently troubleshooting the navigation in IE 10 using their example: https://getbootstrap.com/docs/4.0/examples/jumbotron/ After checking it on IE 10, I noticed that th ...

Which Web Browsers Support Canvas and HTML5?

Currently working on a project that involves using the HTML5 Canvas element. I am curious about which major browsers (including specific versions) actually support the Canvas tag. I am not interested in hearing about IE. In this tutorial Drawing shapes - M ...

Unable to highlight text within a div container

I am currently facing an issue with my layout that involves three columns stacked to the left and four inner columns with three floated left and one floated right. This configuration is causing a problem where I cannot select any text on the page. Removing ...