How can you keep the footer
bottom of the page always, but without using fixed or absolute, because several cases can occur:
In the event that the content is not enough to fill the page, the footer does not stay below unless you put an position: fixed; bottom: 0
orposition: absolute; bottom: 0
But if I put one of those two, since the content is larger than the screen, the footer is always visible, in the case of fixed it scrolls but it always stays on the screen, but in the case of putting absolute, when it goes down it stays through the content medium.
<html>
<body>
<header style="background:grey">Header</header>
<div style="background:yellow">Contenido</div>
<footer style="background:green">tiene que estar abajo pero no se queda abajo siempre...</footer>
</body>
</html>
For layout issues almost always flexbox is the solution. In this case you can put the
body
as a container and occupy the entire height and put the valueflex
in the propertydisplay
, you also have to order the elements vertically withflex-direction: column
; then the content would have the propertyflex: 1
(which is equivalent toflex: 1 1 0
) so that it expands, occupying all the remaining space.I use the same HTML as your example but I would use a
div
container to leave thebody
clean.