Skip to content Skip to sidebar Skip to footer

Horizontally And Vertically Center Div In The Middle Of Page With Header And Footer Stuck To Top And Bottom Of Page

I'm trying to make a page where I have a fixed height header and footer. The header is at the top of the screen (100% width) and the footer is at the bottom (100% width). I want to

Solution 1:

I ended up starting over and trying a different approach. The working solution is found in the new jsfiddle below. The idea was to separate the header and footer from the content area so that they would sit on top and bottom. Then it became much easier to center the content area in the space between those (with some hacks for older versions of IE).

http://jsfiddle.net/UYpnC/5/

Solution 2:

Try something like this:

.main { min-height: 500px }

http://jsfiddle.net/VrfAU/8/

Solution 3:

I used the css property z-index, which controls the stack order to fix this: I also used position: fixed to fix the header and footer:

I put

#header {
background: black;
width: 100%;
height: 66px;
position:fixed;
overflow: hidden;
z-index: 20;}


.main_wrap {
    display: table;
    width: 100%;
    height: 100%;
    margin-top: -88px;
    vertical-align: middle;
    position: relative;
    z-index: -1;
}
#footer {
background: black;
width: 100%;
position: relative;
font-size: 85%;
color: #d0d6e0;
margin-top: -22px;
position: fixed;}

Post a Comment for "Horizontally And Vertically Center Div In The Middle Of Page With Header And Footer Stuck To Top And Bottom Of Page"