Home >Web Front-end >CSS Tutorial >How to Anchor a Div to the Bottom of Dynamic Page 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%; }
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%; }
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!