1

There is lots of info to get footer 100% wide or to extend 100% to bottom of browser.

My problem is a little different.

All the content of my site is wrapped in max-width container. But client wants the footer to be 100% wide and then if the page info is short, the footer must stretch to bottom of page.

So I have to put the footer outside the main container so that it can go right across the width of the page. But this means I can't use the

html , body {height:100%;}

option because making the footer 100% high will not help as it is outside main container.

So, ignoring the main container, how do I tell the standalone 100% wide footer to fill to the page to the bottom of the browser if the page is too short to fill the screen from top to bottom? How do i get the footer to fill that gap on the bottom?

Here is a simple copy of the code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<style>

    #main {
        height: 100px;
        max-width: 900px;
        background-color: blue;
        margin: auto;
    }

    footer {
        width: 100%;
        background-color: lightblue;
        color: white;
    }

</style>

</head>

<body>

        <div id="main">
        </div>

        <footer>
            Footer content
        </footer>

</body>
</html>

How do I get the lightblue footer to go all the way to the bottom?

And please note that I don't want the footer to stick to the bottom, I need it to extend to the bottom of the browser from where ever it is on the bottom of the page.

4

1 回答 1

0

jsFiddle 演示

//css //
footer {
    width: 100%;
    background-color: lightblue;
    position:absolute;
    color: white;
    bottom:0;
}

// jQuery //
$(function () {
    var mainHt = $('#main').height();
    $('footer').css('top', mainHt);
});
于 2013-08-13T16:42:22.907 回答