Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create div to fill all space between header and footer div

Tags:

css

html-table

I'm working on moving from using tables for layout purposes to using divs (yes, yes the great debate). I've got 3 divs, a header, content and footer. The header and footer are 50px each. How do I get the footer div to stay at the bottom of the page, and the content div to fill the space in between? I don't want to hard code the content divs height because the screen resolution can change.

like image 914
Jeremy Avatar asked Oct 15 '08 21:10

Jeremy


People also ask

How do I make a div take all space?

The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.

How do I add space between header and footer in html?

Go to ATO>Style & edit Footer and cut all the formatting out of the Footer Style box. Now Go to ATO>Add HTML/CSS Inserts>CSS Inserts and past in into that box with a selector of td#footer p and add a top margin. It would look something like the following.

How can I add space after div in html?

In case you want additional space ( more than the default ) between div rows then you can add the following code before/after the start of the div row depending on where you want the additional space. This is easier but will add a fixed amount of gap.


1 Answers

Flexbox solution

Using flex layout we can achieve this while allowing for natural height header and footer. Both the header and footer will stick to the top and bottom of the viewport respectively (much like a native mobile app) and the main content area will fill the remaining space, while any vertical overflow will be scrollable within that area.

See JS Fiddle

HTML

<body>   <header>     ...   </header>   <main>     ...   </main>   <footer>     ...   </footer> </body>   

CSS

html, body {   margin: 0;   height: 100%;   min-height: 100%; }  body {   display: flex;   flex-direction: column; }  header, footer {   flex: none; }  main {   overflow-y: scroll;   -webkit-overflow-scrolling: touch;   flex: auto; } 
like image 189
Reggie Pinkham Avatar answered Sep 28 '22 02:09

Reggie Pinkham