Securing 100% height of content area

Hi there…

Having this issue which probably has an easy fix, but i`m stuck

Got a content area which off course is a div with a sidebar inside of it… Works and looks great. A footer is aligned to the bottom of the screen. Not fixed but pushed down by the content area. However, since my content area has a border assigned to it I would like for the content area to go all the way down to the bottom at all times no matter how big a screen you´re displaying the page on and regardless of how much content is actually inside the area. I´m fairly confused cause since my footer is pushed down the border should go all the way down. But it doesn´t… Is it a floating issue?

You experts have seen this before. I´m sure of it… Please help

Assigned the following values to my content area:

#page #central {
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
margin-top:15px;
border-top-right-radius:20px;
-moz-border-top-right-radius:20px /* Firefox 3.6 and earlier */;
-webkit-border-top-right-radius:20px;
border-top-left-radius:20px;
-moz-border-top-left-radius:20px /* Firefox 3.6 and earlier */;
 -webkit-border-top-left-radius:20px;
padding:15px;
height:auto !important;
height: 100%;
min-height:100%;
bottom: 0;
top: 0;
position: relative}

Idea was that the content area is relative to my header and footer off course. But does it need to be?

Hi,

Welcome to Sitepoint :slight_smile:

Please first read the CSS faq on 100% height and the CSS faq on a sticky footer (see my sig) which will explain the obstacles that you need to overcome and then once you have digested them come back here and post your queries (if you still have them) along full html and css.

I’ll quickly point out a few quick flaws in your logic in that little snippet you posted.


border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc; 
margin-top:15px; 
padding:15px; 
height: 100%; 

So here we have a div that (may be) a minmum of 100% high but you have also added 15px padding and a top border. Therefore assuming the min-height is working (more of this in a minute) then you now have an element that is 100% + 30px + 1px tall. So to start with you have an element that can never fit into the required space because 100% is a s big as it gets and therefore the contetn will be taller than the space you want it to occupy.

This code:


#page #central { 

You can’t apply min-height in percentages to an element unless the parent element has a fixed height (i.e. a height that is not dictated by its content and not one that is height auto or only defined by min-height). That means that #page must be height:100% (assuming its parent follows the same rules above) and therefore the layout would be limited to 100% height and wouldn’t be allowed to grow with content.

Specifying a 100% height on an element that isn’t the first element on the page will also mean that the element will be too big because it will be 100% tall from where it starts on the page.

This code fails in IE7:


height:auto !important; 
height: 100%; 
min-height:100%;

IE7 doesn’t like that construct and does weird things so separate the rules as only ie6 doesn’t understand the min-height:

e.g.


html, body {
	height:100%;
	margin:0;
	padding:0;
}
#outer {min-height:100%}
* html #outer { height:100% }/* ie6*/

It’s actually less code anyway so its a no brainer.

If you wnat a 100% element and it needs border all around then you have to be creative and you have to start from top to bottom and use the rules I have set out above. With a little creativity you can end up with something like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sticky Footer at Bottom</title>
<style type="text/css">
html, body {
	height:100%;/* needed to base 100% height on something known*/
	text-align:center;
	margin:0;
	padding:0;
}
h1, h2, p { padding:0 10px; }
#outer {
	width:660px;
	background:#ffc;
	margin:auto;
	min-height:100%;
	margin-top:-10px;/*footer height - this drags the outer 40px up through the top of the monitor */
	text-align:left;
	clear:both;
	border:5px solid #000;
}
* html #outer { height:100% }
#header {
	background:red;
	border-top:10px solid #000; /* soak up negative margin and allows header to start at top of page*/
}
/*Opera Fix*/
body:before {/* thanks to Maleika (Kohoutec)*/
	content:"";
	height:100%;
	float:left;
	width:0;
	margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}
#outer:after {/* thank you Erik J - instead of using display table for ie8*/
	clear:both;
	display:block;
	height:1%;
	content:" ";
}
</style>
</head>
<body>
<div id="outer">
		<div id="header">
				<h1>100% with border</h1>
		</div>
		<p>test</p>
		<p>test</p>
</div>
</body>
</html>

If you want the element to start some way down the page and then go to the bottom you could use the same approach but just rub out the background at the top with a background colour on the elements at the top. There are other methods of creating borders and backgrounds that start from some way down the page a go to the bottom but they are quite complex.

Thing is… I have a sticky footer (which actually sticks quite nicely) which is 100% width (meaning stretching across the whole screen, regardless of screensize), but the wrapper is only 960px wide. I suspect the issue can be here…

Followed your recipe (which involved an equal width for wrapper and footer), but this hasn´t changed much. Well it did mess up my layout a couple of times, but when i completed the coding, I was back to square one. Except there´s no padding in the content area now. Would you be willing to go through the whole code and guide me through a fix?

in short terms… my footer is outside the wrapper… I can imagine for this to be a problem, but must be possible. If i put it inside the wrapper I cannot accomplish fullscreen width for the footer. And I want it :slight_smile:

Hmm, what to do?

Hi,

The footer in my example is outside the wrapper and can be 100% width if required. I can guarantee that your sticky footer version will be broken in multiple browsers as the only fullproof method is based on the one I have documented in the faq and have been using in similar form since 2003.:slight_smile: All those elements must be in place correctly as stipulated or one browser on another will be broken.

I’d need to see your full css and html (or a link) or at least a drawing to give specific advice.

Here is an older example with a wide footer and even wide header.

Not saying your way doesn´t work… I just can´t get it to work on my site, and probably cause I´m overlooking a key element :slight_smile:

It is a work in progress, and it´s a modified theme in concrete5, but here goes… Appreciate your help, Paul :slight_smile:

My site

Get rid of the push div for a start as the negative margin is accounted for in the header.


.push{display:none}

Im working on the other issues.

Ok this is rough but add this code to the end of the css or test live with CSS edit or css terminal in Firefox.


/*Opera Fix*/
body:before {
	content:"";
	height:100%;
	float:left;
	width:0;
	margin-top:-32767px;
}
/* ie8+ fix*/
#page:after {
	clear:both;
	display:block;
	height:1%;
	content:" ";
}

.push { display:none }
#page {
	border-left: 1px solid #CCCCCC;
	border-right: 1px solid #CCCCCC;
	border-top:none;
	-webkit-border-radius:0;
	-moz-border-radius:0;
	box-shadow: -6px -3px 5px #CCCCCC;
}
#headerSpacer {display:none; }
#page #header {
	background:#fff url(images/centralshadowtop.png) 0 100%;
	margin:0 -11px;
	padding:0 11px 40px;
	position:relative;
	zoom:1.0;
	width:auto;
}
#page #header {
	border-top:194px solid #fff;
	padding-bottom:50px;
}
#central {
	border:none;
	box-shadow:none;
	height:auto;
	box-shadow:none;
	margin:0;
	min-height:0;
}

*+html #headerNav{width:450px;}
* html #headerNav{width:450px;}



As I said before you only have one shot at 100% height and you must use the page wrapper for your 100% high shadow and border and then rub it out where you don’t want it to show. The only downside is that for the top round corners and shadows of #central you will need to use an image because although I could add a top shadow to central it will then sit on top of the page shadow and there will be a slight join that can’t be smoothed out. It wasn’t that bad a join but I noticed it and it spoilt the effect.

The shadow image should be applied at the bottom of the header as indicated here.


#page #header {
background:#fff url(images/centralshadowtop.png) 0 100%;
}


I also fixed the footer so it works in iE6/7/8/ and opera as yours was broken as said it would be :slight_smile: You also need to set a width for your top nav for IE6 and 7 and I have included 2 hacks for them.

You can see a similar approach was used in this old demo but refer to the faq for the updated sticky footer code.

I’ve just edited a couple of styles above so make sure you have the latest rules.

Will test it later today… Thanks a million, Paul. You saved my day and you´re a true go-to-guy :slight_smile:

my footer is missing?

That’s because you told it to go away here:


#footer, .push {
    display: none;
}

I just set the psuh to go away:


.push {
    display: none;
}

Of course you should actually remove it from the html altogether :slight_smile:

off course… :slight_smile: This is brilliant, and all is going according to plan now… Now it´s just the question about the top border shadow. May be a stupid question, but where to find the png-file containing the border?

#page #header {
background:#fff url(images/centralshadowtop.png) 0 100%;
}

This i don´t quite follow? Where do i put this? Just in the end of my main.css?

Hi,

Create an image like the one I have attached (or use the one I attached) and then upload it and set the correct path here.


#page #header {
background:#fff url(top.gif) no-repeat 50% 100%;
}


You will need to hide the image from IE8 and under as they don’t have the shadows. So create a conditional stylesheet for IE8 and under and remove the image and perhaps apply a border-top to the central div.

e.g.


<!--[if lte IE 8]>
<style type="text/css">
#page #header{background:#fff}
#central{border-top:1px solid #ccc}
</style>
<![endif]-->

The above code goes in the head of the document and not in the CSS file. Most users create a separate css file and link to it via the conditional comments for IE versions as required.

YOU´RE THE MAN!