Question

I have this HTML:

<div class="page">
    <div class="content">
        <p>Lorem ipsum dolor sit amet...</p>
        <p>Etiam condimentum lorem faucibus feugiat egestas...</p>
    </div>
    <div class="footer">
        <p class="text-center">Sticky footer with centered text?</p>
    </div>
</div>

And this CSS:

body {
    background: #222;
    margin: 0;
    padding: 0;
}
p {
    margin: 0 0 20px;
}
.page {
    margin-left: 200px;
    background: #fff;
    min-height: 1200px;
    padding: 20px 20px 0;
}
.footer {
    position: fixed;
    bottom: 0;
    background: #eee;
    width: 100%;
    padding: 20px 20px 0;
    margin: 0 -20px;
}
.text-center {
    text-align: center;
}

Here's the jsFiddle (better than thousand words):

http://jsfiddle.net/xJ5uV/1/

How do I center the sticky footer to white page (.page), given that problematic margin-left that's causing the unalignment?

Thanks in advance!

Was it helpful?

Solution

Change your margin to auto

.page {
    margin: 0 auto;
    ...
}

EDIT

My bad, I misunderstood the question, you can achieve it with the following:

.footer {
    width: calc(100% - 200px);
    margin-left:-20px;
}

I placed it in a fiddle for you. Calc is available in IE 9+.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top