I want to vertically align a div element in HTML to the bottom of a viewport, but also horizontally align the same div to the document/page, or an element thereof.
For instance, say I have a div as such:
<html>
<head>
<style type="text/css">
* {
margin: 0;
}
#wrapper {
margin: 0 auto;
width: 1000px;
min-height: 2000px;
background: #FF0000;
}
</style>
</head>
<body>
<div id="wrapper">wrapper</div>
</body>
</html>
I would like to make a new div, that is affixed to the bottom of the viewport, but is aligned with the div shown. For the sake of brevity, let's assume the div I want to align is the same width as the one shown, and I want to left align it with the one shown.
My naive attempt is as follows:
<html>
<head>
<style type="text/css">
* {
margin: 0;
}
#wrapper {
margin: 0 auto;
width: 1000px;
min-height: 2000px;
background: #FF0000;
}
#footer {
position: fixed;
bottom: 0;
left: 50%;
width: 1000px;
height: 100px;
margin-left: -500px;
background: #00FF00;
}
</style>
</head>
<body>
<div id="wrapper">wrapper</div>
<div id="footer">footer</div>
</body>
</html>
This solution works so long as the viewport is larger than 1000px wide. Once the window is made smaller than 1000px, the solution breaks; the footer no longer scrolls horizontally with the rest of the page. Also note that if the document is "taller" than the viewport, the footer div should remain affixed to the bottom of the viewport.