Note: This answer dates from 2010. Consider position: sticky
in 2021, as mentioned in another answer.
Use position: fixed
on the div
that contains your header, with something like
#header {
position: fixed;
}
#content {
margin-top: 100px;
}
In this example, when #content
starts off 100px below #header
, but as the user scrolls, #header
stays in place. Of course it goes without saying that you'll want to make sure #header
has a background so that its content will actually be visible when the two div
s overlap. Have a look at the position
property here: http://reference.sitepoint.com/css/position
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…