"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Create a Sticky Footer in CSS Without Absolute Positioning?

How to Create a Sticky Footer in CSS Without Absolute Positioning?

Posted on 2025-03-23
Browse:276

How to Create a Sticky Footer in CSS Without Absolute Positioning?

How to Create a Responsive Footer Using CSS

Maintaining the footer at the page's bottom is a common web design requirement. However, some users encounter difficulties using the "absolute" positioning property. This article will guide you through the correct CSS implementation to achieve a sticky footer effect without disrupting your layout.

Issue Background

Users attempting to fix their footer position unsuccessfully have typically applied the following code:

position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;

Proposed Solution

To resolve the issue without using plugins or additional HTML elements, follow these steps:

  1. Add the following CSS rules to your stylesheet:
html {
    position: relative;
    min-height: 100%;
}
body {
    margin: 0 0 100px; /* bottom = footer height */
}
#bottom-footer {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 100px;
    width: 100%;
}
  1. Ensure that the height specified in "body {margin}" matches the actual height of the footer element (e.g., 100px).

Note: It's recommended to use the HTML element ID "#bottom-footer" for targeting instead of "footer #bottom-footer," as the latter may conflict with your original CSS styling.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3