I wanted a flexible sticky footer, which is why I came here. Top answers got me in the right direction.
The current (2 Oct 16) Bootstrap 3 css Sticky footer (Fixed size) looks like this:
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
As long as the footer has a fixed size, the body margin-bottom creates a push to allow a pocket for the footer to sit in. In this case, both are set to 60px. But if the footer is not fixed and exceeds 60px height, it will cover your page content.
Make Flexible: Delete the css body margin and footer height. Then add JavaScript to get the footer height and set the body marginBottom. That is done with the setfooter() function. Next add event listeners for when the page first loads and on resizing that run the setfooter. Note: If you footer has an accordion or anything else that triggers a size change, without a resize of window, you must call the setfooter() function again.
Run the snippet and then fullscreen to demo it.
function setfooter(){_x000D_
var ht = document.getElementById("footer").scrollHeight;_x000D_
document.body.style.marginBottom = ht + "px";_x000D_
}_x000D_
_x000D_
window.addEventListener('resize', function(){_x000D_
setfooter();_x000D_
}, true);_x000D_
window.addEventListener('load', function(){_x000D_
setfooter();_x000D_
}, true);
_x000D_
html {_x000D_
position: relative;_x000D_
min-height: 100%;_x000D_
}_x000D_
.footer {_x000D_
position: absolute;_x000D_
bottom: 0;_x000D_
width: 100%;_x000D_
_x000D_
/* additional style for effect only */_x000D_
text-align: center;_x000D_
background-color: #333;_x000D_
color: #fff;_x000D_
}_x000D_
_x000D_
_x000D_
_x000D_
body{_x000D_
/* additional style for effect only not needed in bootstrap*/_x000D_
padding:0;_x000D_
margin: 0;_x000D_
}
_x000D_
<div>_x000D_
Page content_x000D_
<br> <br>_x000D_
line 3_x000D_
<br> <br>_x000D_
line 5_x000D_
<br> <br>_x000D_
line 7_x000D_
_x000D_
</div>_x000D_
_x000D_
_x000D_
<footer id="footer" class="footer">_x000D_
<div class="container">_x000D_
<p class="text-muted">Footer with a long text, so that resizing, to a smaller screen size, will cause the footer to grow taller. But the footer will not overflow onto the main page.</p>_x000D_
</div>_x000D_
</footer>
_x000D_