Same as I suggested in Footer always at the bottom of the page , just change the selectors for your elements.
You will have to combine position: relative
with absolute
, it's not obscure, just that the element "father" (in my case I created one more element, .main
) is in relative
, it would be something like:
I added a button for you to test that the footer will accompany the content if the scrollbar appears
var content = document.getElementById("content");
var adicionar = document.getElementById("adicionar");
adicionar.onclick = function () {
var novo = document.createElement("p");
novo.textContent = "Foo Bar Baz, " + (new Date());
content.appendChild(novo);
};
html, body {
height: 100%; /* é necessário definir o height 100% no html, body ou qualquer elemento que estiver entre o body e o .container */
padding: 0;
margin: 0;
}
.main {
position: relative; /*faz a mágina :)*/
min-height: 100%; /* define a altura minima*/
background: #fcfcfc;
}
.main > footer {
background: #0c0c0c;
color: #fff;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
<div class="main">
<header></header>
<div id="content">
Todo conteúdo vai aqui<br>
<button id="adicionar">Adicionar conteudo</button>
</div>
<footer>Rodapé</footer>
</div>