Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS 100% height layout

Tags:

css

height

layout

I know this is a sort of a common problem, and I looked up some solutions, but couldn't find exactly what I was looking for.

I would like to convert this to a tableless layout.

enter image description here

Note: header and footer have to be set to a fixed height in pixels (50px is ok).

The main problem I'm having is that I cannot get that "big box" in the middle to behave like it does when it's done with tables. There are solutions which work OK for a variable length content (text, images), but I would like this box look and behave like a box - with borders, rounded corners and all.

like image 538
ile Avatar asked May 28 '11 00:05

ile


People also ask

How do you use 100 height in CSS?

With the advent of the CSS flex model, solving the 100% height problem becomes very, very easy: use height: 100%; display: flex on the parent, and flex: 1 on the child elements. They'll automatically take up all the available space in their container.

How do I make my page full height in CSS?

For a responsive full page height, set the body element min-height to 100vh. If you set a page width, choose 100% over 100vw to avoid surprise horizontal scrollbars.

How do you make a div 100 height?

container div has two parent elements: the <body> and the <html> element. And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.

How do I Auto adjust height in CSS?

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow.


1 Answers

You can do it with table style CSS properties, but still retain table less markup (which is still a win).

Example

Example

HTML

<div id="container">     <div id="header"><div>header</div></div>     <div id="content"><div>content</div></div>     <div id="footer"><div>footer</div></div> </div> 

CSS

html, body {     height: 100%;      padding: 0;     margin: 0; }  #container {     display: table;      width: 100%;     height: 100%;     border: 1px solid red;        text-align: center; }  #container > div {        display: table-row;        width: 100%; }  #container > div > div {        display: table-cell;        width: 100%;     border-radius:10px;   }  #header > div {     height:50px;      border:solid 2px #aaa; }  #content > div {     height: 100%;         background:#f0f4f0;      border:solid 2px #5a5; }  #footer > div {     height:50px;      border:solid 2px #a55; } 

jsFiddle.

like image 157
alex Avatar answered Oct 23 '22 23:10

alex