On my page I have two DIVs, "main" and "footer":
<div id="main"> stuff... </div>
<div id="footer"> stuff... </div>
I aligned <div id="footer">
to the bottom of the page this way:
#footer {
position: fixed;
width:100%;
bottom:0;
}
What’s the best way to make <div id="main">
take up all the space from top of page to top of <div id="footer">
?
For the special case where the window is so small that <div id="footer">
takes up the entire page space, <div id="main">
can be moved off the page entirely, or be aligned at the top of the page, I don’t care as long as it doesn’t break anything.
Edit: Is it possible to do this using CSS only ?
I can’t set the height of the "footer" to a fixed value, it must be determined by the browser based on its content.
2
Answers
Since you haven’t specified the height of the footer let’s just assume it has a height of 5rem. (you could set it to pixels if you wish )
Please notice how to calc function was used in the height of the main section to subtract 5rem allocated to the height of the footer.
I wanted to keep the CSS simple so I have set the height of both the footer and header heights in percentages. This way the height and width would stay the same for all the devices.