Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content appearing behind fixed header

I fixed the header section of a website, but the first div of the page appears behind the header; instead of starting from the end of the header.

like image 762
adeniyi makinde Avatar asked Jun 20 '12 19:06

adeniyi makinde


People also ask

How do you fix a fixed header position?

Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.

Does position fixed take up space?

By using position: fixed on an element like the header, the element is removed from the stack and positioned relative to the browser window. That means it no longer takes up space and any elements positioned after it will adjust to fill up that area.


1 Answers

When you apply position: fixed or position: absolute the element is being removed from the document flow, so the elements that come after treat it as a non-existent. That's why your div jumps up. To fix that apply a margin-top that equals to your header height - http://jsfiddle.net/2xjES/

like image 74
Zoltan Toth Avatar answered Nov 03 '22 20:11

Zoltan Toth