This question has already been answered:
This is not a duplicate of the question “ How to always press footer to the bottom of the screen? ". There the basement is attached unconditionally. I also need to attach only if the page does not fit vertically on the ekan.
How to make up <footer>
satisfying the conditions described below?
- In accordance with the principle of rubber layout, its width is always equal to the width of the window (This condition excludes positioning).
- If the height of the window is greater than the height of the content, then the footer is pressed to the bottom of the window, forming a space with the main content (it looks better than the space after the footer).
- If the height of the window is less than the height of the content, then the vertical scrolling ends on the footer.
To save you time, I did a simple jsfiddle template .
<header></header> <main>Если ничего не ввести, то не отображается даже при заданной высоте. </main> <footer></footer> header{ height: 50px; width: 100%; background: #F5A9A9; } main{ //display: block; // Кроссбраузерность для IE height: 150px; width: 100%; background: #F5F6CE; } footer{ height: 50px; width: 100%; background: #E0F8E6; }