<html>
<body>
<div class="fixed-top-bar" style="position:fixed"></div>
<div class="content" style="position:static"></div>
</body>
</html>
In my browser, both div starts from top left of the browser.
In firebug, I set both div with “display: block” so each div element should take a row of space.
Why do I see them stacked on the top left? How can I make it look normal?
When applying
position: fixed, the element gets pulled out of the natural flow of the page. This causes all other elements to ignore that elements position. That’s why the staticdivlies below the fixeddiv.The fixed
div‘s position relates to the parent element which in this case isbody. Since you didn’t give it anylefttoprightbottomposition data, it just behaves liketop: 0; left: 0;which happens to be the exact same postion where your staticdivlies below.To resolve this, I’d simply add the same amount of
padding-topto thebodyas the fixeddivis high.You can read more about this here: https://developer.mozilla.org/en/CSS/position
By the way, a
divnaturally behaves as if you’d give itdisplay: block. In fact, that’s its only default styling.