gib65
12-04-2015, 06:16 PM
Hello,
I'm having a problem sizing a div properly.
I've got 3 divs on the page: a header, a body, and a footer. I'm positioning and sizing them as follows:
<div id="header" style="height: 75px; width: 100%;">
header
</div>
<div id="body" style="height: calc(100vh - 105px); width: 100%;">
body
</div>
<div id="footer" style="position: absolute; bottom: 0; height: 30px; width: 100%;">
footer
</div>
This seems to work: I get a header at the top 75px high, I get a footer at the bottom 30px high, and I get the body div in the middle which takes up the remaining height by calculating 100vh minus the sum of the header and footer heights.
The problem is when I resize the browser. The header stays at the top at 75px, the footer stays at the bottom at 30px, but the body div keeps its original height, effectively cropping some of its content now that the browser is smaller. I figure the problem is that when I subtract 105px from 100vh, the result of that calculation is in pixels. Being in pixels, it will not adjust the height when the browser resizes.
So what I'm wondering is: is there a way of calculating the remaining height (after header and footer heights have been set) in percentage?
I know I can handle this in javascript, but I'd really like to practice my CSS skills. Any help will be much appreciated.
I'm having a problem sizing a div properly.
I've got 3 divs on the page: a header, a body, and a footer. I'm positioning and sizing them as follows:
<div id="header" style="height: 75px; width: 100%;">
header
</div>
<div id="body" style="height: calc(100vh - 105px); width: 100%;">
body
</div>
<div id="footer" style="position: absolute; bottom: 0; height: 30px; width: 100%;">
footer
</div>
This seems to work: I get a header at the top 75px high, I get a footer at the bottom 30px high, and I get the body div in the middle which takes up the remaining height by calculating 100vh minus the sum of the header and footer heights.
The problem is when I resize the browser. The header stays at the top at 75px, the footer stays at the bottom at 30px, but the body div keeps its original height, effectively cropping some of its content now that the browser is smaller. I figure the problem is that when I subtract 105px from 100vh, the result of that calculation is in pixels. Being in pixels, it will not adjust the height when the browser resizes.
So what I'm wondering is: is there a way of calculating the remaining height (after header and footer heights have been set) in percentage?
I know I can handle this in javascript, but I'd really like to practice my CSS skills. Any help will be much appreciated.