I have a very simple structure and layout.
There is a #header
and a #footer
with a #body-container
between them. The #header
is position: fixed
.
The #body-container
has a margin-top: 3.1em
to make room for the #header
, which has height: 3em
, but that doesn't work the way I thought it would. Even though the #header
is not a child of the container, it won't render above the container (i.e. in the margin).
Why doesn't the #header
render in the top margin of the #body-container
? How can I achieve the desired effect?
You can fiddle with it here, and the code is here for reference:
HTML:
<body>
<div id="header">
</div>
<div id="body-container">
<div class="left">
</div>
<div class="right">
</div>
</div>
<div id="footer">
</div>
</body>
CSS:
div {
margin-bottom: 0.1em;
background-color: #99ccff;
}
#body-container {
background-color: white;
margin-top: 1.1em;
width: 20em;
height: 35em;
}
.left {
width: 2.5em;
height: 100%;
float: left;
}
.right {
margin-left: 2.6em;
height: 100%;
}
#header {
background-color: #99eeee;
position: fixed;
height: 3em;
width: 20em;
z-index: 1;
}
#footer {
height: 3em;
width: 20em;
}