Home > Web Front-end > CSS Tutorial > How to Anchor a Div to the Bottom of Dynamic Page Content?

How to Anchor a Div to the Bottom of Dynamic Page Content?

Susan Sarandon
Release: 2024-12-13 00:47:10
Original
864 people have browsed it

How to Anchor a Div to the Bottom of Dynamic Page Content?

Anchoring a Div to the Bottom of Page Contents with Dynamic Content

Problem:

You need to create a div (#footer) that remains at the bottom of the page's content, even when scrollbars erscheinen. Unlike fixed positioning, it should only be positioned at the end of the actual content, not the viewport.

Current Implementation:

#footer {
    position: absolute;
    bottom: 30px;
    width: 100%;
}
Copy after login

This method positions the div at the bottom of the viewport, but it remains fixed there even when the page is scrolled, resulting in misalignment with the content.

Solution: Position Fixed with Bottom Adjustment

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

By setting the position to fixed, the div becomes anclado to the bottom of the browser window. The bottom property ensures that the div is positioned at the absolute base of the page, regardless of scrollbar visibility.

This positioning allows the div to remain aligned with the bottom of the content, as illustrated in the example.

The above is the detailed content of How to Anchor a Div to the Bottom of Dynamic Page Content?. 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