Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS footer fixed position based on minimum height

Tags:

html

css

I've looked on here and on various tutorial but can't the effect I need.

So if the page content is less high than 600px I want the footer fixed below a container that is that height.

But if the content increases the container height to beyond 600px then the footer should be pushed down the page by the container.

I've tried using min-height to avail, my html look like this

<body>
<div id="shell">
<div id="container">
Content
</div>
<div id="footer">Footer</div>
</div>
</body>

I won't bother posting the CSS as it just doesn't come close.

like image 309
Guesser Avatar asked Dec 01 '25 18:12

Guesser


1 Answers

You can do this by CSS Trick,

/* CSS Code */

body, html{
    padding:0;
    margin:0;
    height:100%;
}

.wrapper{
    min-height:100%;
    position:relative;
}

.container{
    width:960px;
    margin:0 auto;
    padding-bottom:100px;
}

.header{
    height:100px;
    background-color:#066;
}

.footer{
    position:absolute;
    bottom:0;
    height:100px;
    background-color:#006;
    width:100%;
}

<div class="wrapper">
    <div class="container">

        <div class="header">
            Header
        </div>

        <div class="body">

        </div>


    </div>

    <div class="footer">
        Footer
    </div>

</div>

Here is my Fiddle File

like image 88
Roy Sonasish Avatar answered Dec 03 '25 07:12

Roy Sonasish