Home >Web Front-end >CSS Tutorial >How Can I Position a Div at the Bottom of Scrollable Page Content Without Using `position: fixed`?

How Can I Position a Div at the Bottom of Scrollable Page Content Without Using `position: fixed`?

Linda Hamilton
Linda HamiltonOriginal
2024-12-18 16:30:11837browse

How Can I Position a Div at the Bottom of Scrollable Page Content Without Using `position: fixed`?

Positioning Div at the Bottom of Page Content with Scrollbars

Unlike traditional methods that anchor a div to the bottom of the viewport, you seek a solution where the footer stays fixed at the base of the content, even when scrollbars are present. Complicating matters, the #footer div should not exhibit fixed positioning.

To achieve this, the precise functionality you require can be achieved through the following CSS:

#footer {
    position: fixed;
    bottom: 0;
    width: 100%;
}

Position: fixed denotes an element that remains in place as the page scrolls, ensuring the footer stays grounded at the bottom of the content.

By setting bottom to 0, we anchor the footer to the lowermost end of the window, ensuring it remains aligned with the page content's base.

Finally, width: 100% ensures the footer spans the entire page width, effectively creating the desired effect.

Here's a live demonstration: https://jsfiddle.net/uw8f9/

The above is the detailed content of How Can I Position a Div at the Bottom of Scrollable Page Content Without Using `position: fixed`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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