Home > Web Front-end > CSS Tutorial > How Can I Fix My Footer to the Bottom of the Page Regardless of Content Height?

How Can I Fix My Footer to the Bottom of the Page Regardless of Content Height?

Mary-Kate Olsen
Release: 2024-12-20 03:09:11
Original
334 people have browsed it

How Can I Fix My Footer to the Bottom of the Page Regardless of Content Height?

Fixing Footer to Bottom of Page

In your attempt to keep the footer fixed at the bottom of your web page, you have tried various methods, such as "bottom:0px" and "position:absolute," without satisfactory results. Here's a solution to ensure your footer stays at the bottom of the page regardless of screen size:

  1. Modify Footer CSS:
#footer {
    position: fixed; 
    bottom: 0; 
    left: 0; 
    right: 0;
    height: [desired height of footer, e.g., 50px];
    margin-bottom: 0;
}
Copy after login
  1. Add Margin to Body:

To prevent the footer from overlapping with the page content, add a margin to the body:

body {
    margin-bottom: [same height as footer, e.g., 50px];
}
Copy after login

This ensures that the page remains scrollable, even with the fixed footer. Adjust the height values in the CSS code to suit your requirements.

Example Code:

<div>
Copy after login
#footer {
  background-color: red;
  position: fixed;
  bottom: 0px;
  left: 0px;
  right: 0px;
  height: 50px;
  margin-bottom: 0px;
}

body {
  margin-bottom: 50px;
}
Copy after login

This code fixes the footer to the bottom of the page, ensuring it's visible even with limited content.

The above is the detailed content of How Can I Fix My Footer to the Bottom of the Page Regardless of Content Height?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template