/    Sign up×
Community /Pin to ProfileBookmark

Stretch footer to bottom of browser window

I’m not looking for a Sticky Footer solution here. What I want is for the footer, the final containing div, to extend to the bottom of the browser window.

Here’s the code. If I have to use Javascript, that’s fine. This doesn’t have to be a pure CSS solution.

Thanks!

[CODE]*{margin:0;padding:0;}

html {
}

body {
background: #000 url(../images/bg_patt.gif) repeat left top;
}

#header {
margin:0px auto;
height:68px;
width:818px;
overflow:hidden;
background-color:pink;
}

#navbar {
margin:0px auto;
height:39px;
width:818px;
overflow:hidden;
background-color:teal;
}

#main_content {
margin:0px auto;
overflow:hidden;
width:818px;
background-color:yellow;
}

#footer {
margin:0px auto;
height:39px;
width:818px;
padding-bottom:60px;
background-color:magenta;
}[/CODE]

[CODE] <!–begin header–>
<div id=”header”>
header
</div>
<!–end header–>

<!–begin navbar–>
<div id=”navbar”>
navbar
</div>
<!–end navbar–>

<!–begin main_content–>
<div id=”main_content”>
maincontent
</div>
<!–end main_content–>

<!–begin footer–>
<div id=”footer”>
footer
</div>
<!–end footer–>[/CODE]

to post a comment
CSS

8 Comments(s)

Copy linkTweet thisAlerts:
@Big_O_1_Mar 17.2011 — I'm guessing you're talking about fixed positioning when you say "sticky footer." Try absolute positioning instead:

[CODE]
div#footer
{
position: absolute;
bottom: 0;
}
[/CODE]
Copy linkTweet thisAlerts:
@JPDauthorMar 17.2011 — I appreciate the reply, but, to be clear, I am [B]NOT[/B] looking for a sticky/fixed footer solution.

I just want the footer to extend 100% to fill the vertical space in the browser window.

Thanks again.
Copy linkTweet thisAlerts:
@Big_O_1_Mar 17.2011 — oh, in that case you're going to have to apply a height to the footer using a percentage like 50&#37; or however much you want. Then make the rest of the page have the remaining height.
Copy linkTweet thisAlerts:
@JPDauthorMar 17.2011 — Thanks again, but I don't believe that works. At least not with the code I provided. Are you able to accomplish that using the code I provided? Can you show me an example?

Thanks.
Copy linkTweet thisAlerts:
@Big_O_1_Mar 18.2011 — It worked for me. You just have to set the heights of each container properly. Here's what I used:

[CODE]
*{margin:0;padding:0;}

html {
}

body {
background: #000 url(../images/bg_patt.gif) repeat left top;
height: 100%;
}

#header {
margin:0px auto;
[B]height:15%;[/B]
width:818px;
overflow:hidden;
background-color:pink;
}

#navbar {
margin:0px auto;
[B]height:15%;[/B]
width:818px;
overflow:hidden;
background-color:teal;
}

#main_content {
margin:0px auto;
overflow:hidden;
[B]height: 50%;[/B]
width:818px;
background-color:yellow;
}

#footer {
margin:0px auto;
[B]height:20%;[/B]
width:818px;
[B][I]padding-bottom:60px;[/I][/B]
background-color:magenta;
}
[/CODE]


Remove that padding value. Or you could use a percentage value instead and subtract that value from the footer's height. For example padding-bottom: 3% and height: 17%
Copy linkTweet thisAlerts:
@JPDauthorMar 23.2011 — Thanks again for the response.

I don't think that's going to work for me, since I can't have the main_content div be a fixed height. It needs to expand to contain the content within.
Copy linkTweet thisAlerts:
@NoasITMar 23.2011 — Question: Are you looking for the footer to be at the bottom of the window if the content doesn't fill window? Does this mean if the content extends past the bottom of the window you want the footer not to be visible unless you scroll down?
Copy linkTweet thisAlerts:
@grisgruisMar 30.2011 — To set a custom height locked to somewhere:

CSS---------------

[CODE]body,html{
height:100%;}
#outerbox{
width:100%;
position:absolute; /* to place it somewhere on the screen */
top:130px; /* free space at top */
bottom:0px;} /* makes it lock to the bottom */
#innerbox{
width:100%;
position:absolute;
min-height:100%; !important /* browser fill */
height:auto;} /*content fill */[/CODE]


HTML--------------

[CODE] <div id="outerbox">
<div id="innerbox"></div>
</div>[/CODE]
×

Success!

Help @JPD spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...