If the first container has a defined height, one simple solution would be to make the first container fixed using position: fixed
. You can then adjust the margin-top of the other containers to ensure they start just below the first container:
HTML:
<div id="header">Header</div>
<div id="rest">
<div>Other 1</div>
<div>Other 2</div>
<div>Other 3</div>
</div>
CSS:
div#header{
position: fixed;
width: 100%;
height: 150px;
border: 2px dashed yellow;
background-color: lightyellow;
}
div#rest{
margin-top: 150px;
position: relative;
}
div#rest div{
height: 300px;
border: 2px dashed green;
background-color: lightgreen;
}
The position: absolute;
is used for browsers that do not support fixed positioning. Making it absolute will make it behave like fixed, but it will scroll along with the rest of the page. The position: relative;
on the rest is necessary for z-stacking. Fixing the header container positions it on top of everything else; setting the rest to relative
places it on top of the header again.
View the jsfiddle demo here.
If the header does not have a specific height, you may need to consider using javascript.