How to get fixed margin between body and footer

This should help:

html, body {
    height: 100%;
}
body {
    margin:0px;
    padding: 0px;
}
.wrap {
    height: auto;
    margin: 0 auto -80px; /* footer height + space */
    min-height: 100%;
    padding: 0 0 80px; /* footer height + space */
    box-sizing: border-box;
    overflow: auto;
}
.footer {
    background-color: #111111;
    color: #eeeeee;
    border-top: 1px solid red;
    height: 60px;  /* footer height */
    padding-top: 20px;
    display: block;
    margin-top: 20px; /* space between content and footer */
    box-sizing: border-box;
    position: relative;
    width: 100%;
}
<body>
    <div class="wrap">
        <nav>
            <!-- ... -->
        </nav>
        <section id="sidebar">
            <!-- ... -->
        </section>
        <section id="main">
            <!-- ... -->
            
        </section>
    </div>
    <footer class="footer">
        <div>Some text</div>
    </footer>
</body>


Why you use ":before"?

Your css should look like this:

.footer {
    color: #333;
    font-size: 11px;
    text-align: center;
    vertical-align: bottom;
    margin-top: 120px;
}

Try this example (works fine for me). If it not works - make sure you use css reset.

<!DOCTYPE html>

    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <!-- ... -->
        </head>
        <body>
            <nav style="background:grey;height:100px;">
                <!-- ... -->
            </nav>
            <section id="sidebar" style="background:green;height:100px;">
                <!-- ... -->
            </section>
            <section id="main" style="background:red;height:100px;">
                <!-- ... -->
            </section>
            <footer class="footer" style="background:blue;">
                <div>Some text</div>
            </footer>
        </body>
    </html>

<style>
.footer {
    color: #333;
    font-size: 11px;
    text-align: center;
    vertical-align: bottom;
    margin-top: 120px;
}

</style>

To add a margin between the body and footer, just add this to the style of the footer section: padding:20px 0px 0px 0px;

Keeping the footer at the bottom is more complicated. Try something like this for css:

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

#wrapper{              /*create a div around whole html body
    min-height:100%;
    position:relative;
}

#main{
    padding-bottom:100px; /* Height of the footer element */
}

#footer {
    width:100%;
    height:100px;
    position:absolute;
    bottom:0;
    left:0;
    color: #333;
}

Tags:

Html

Css

Footer