nowiko
nowiko

Reputation: 2557

Create sticky footer using Css

Hello I trying to create sticky footer as described in this beatiful article. But I getting scroll bar on browser, and my footer "slides" out of screen borders. Here is my code:

Html:

<div id="page">
        <div id="header">
            <div id="main_menu">
            </div>
        </div>
        <div id="content">
            fdsfsdfsdfsd
            <div id="push"></div>
        </div>
        <div id="footer"></div>
</div>

CSS:

html, body {
    height: 100%;
}

#content {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -28px;
}

 #push, #footer {
    height: 28px;
     clear: both;
}

Can somebody help me? What I am doing wrong?

Upvotes: 0

Views: 40

Answers (2)

Ron van der Heijden
Ron van der Heijden

Reputation: 15070

You should use a wrapper instead of targetting #content.

html, body, #page {
    height: 100%;
    margin: 0;
    padding: 0;
}
#wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -28px;
}
#push, #footer {
    height: 28px;
    clear: both;
}

#footer {
    background-color: green;
}
<div id="page">
    <div id="wrapper">
        <div id="header">
            <div id="main_menu"></div>
        </div>
        <div id="content">fdsfsdfsdfsd</div>
        <div id="push"></div>
    </div>
    <div id="footer"></div>
</div>

Upvotes: 1

Alex McMillan
Alex McMillan

Reputation: 17952

You'll have some extra margin/padding on the page.. try

html, body {
    margin: 0;
    padding: 0;
}

Upvotes: 0

Related Questions