Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Height of 100% minus #px - Header and Footer

Tags:

The webpage in question looks like this:

// The Header // /*            */ /*  CONTENT   */ /*            */ // The footer // 

Both the header and the footer have fixed heights. Lets say for example that both have a height of 20px. I need to set the content's height to 100% minus 40px (header + footer heights). I know I can do this easily with JavaScript, but it would be cool to learn how to do it with plain CSS, if it's possible.

like image 297
JCOC611 Avatar asked Jan 03 '11 19:01

JCOC611


People also ask

What does CSS height 100% do?

4 Answers. Show activity on this post. height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

How do I get the height of an element in CSS?

height() It returns the current height of the element. It does not include the padding, border or margin. It always returns a unit-less pixel value. Note: The height() will always return the content height, regardless of the value of CSS box-sizing property.

How do I make a div the same size as my body?

Fortunately, it's easy to fix - although this is an Explorer-only solution! Place both DIVs into a container DIV that's set to 100% of page height and set both interior DIVS to 100%. They will fill up the container DIV and the height of both will be equal.


1 Answers

If your browser supports CSS3, try using the CSS element Calc()

height: calc(100% - 65px); 

you might also want to adding browser compatibility options:

height: -o-calc(100% - 65px); /* opera */ height: -webkit-calc(100% - 65px); /* google, safari */ height: -moz-calc(100% - 65px); /* firefox */ 
like image 192
Jim Clouse Avatar answered Sep 28 '22 07:09

Jim Clouse