We press the basement to the bottom. Fixed footer Making a footer
Press the footer to the bottom of the screen. Requirements:
- the footer is pressed to the bottom of the screen when the height of the browser window is greater than the height of the page, regardless of the content
- the footer is in its proper place when the volume of content is greater than the height of the browser window
- works in all popular browsers
- reliability - does not depend on the complexity of the layout
Theory
It is good practice to fill the entire available area of the browser screen with the site (at least in height for designs that are static in width).
Solution
For example, let's take a simple page consisting of two main blocks: main and footer. Let's make sure that the main block takes up the entire area of the browser window, regardless of the amount of content, while pressing the footer to the bottom of the screen so that a vertical scroll bar does not appear in the browser. How we do it:
Step 1
We make 2 blocks: main (main) and basement (footer). We stretch the main container to the entire height of the browser screen (), and we rigidly specify the height of the footer ().
In this case, the total height of the site will be the height of the screen + the height of the footer.
Step 2
The note: When using block layout and floating main blocks (columns) for .hFooter, you should add : both so that the footer is located under the columns.:
HFooter ( clear: both; height: 40px; )
Tested in:
Note 1: If you have already mastered CSS a little, then the question may arise: “Why use an additional element if you can use it?”. The answer is that you can’t just use it here, because... The size of a block is equal to its width and height + the sum of the internal paddings + the sum of the border thicknesses. Link: 100% and will give the height of the site greater than the height of the screen. As a result, even if there is no content at all, the footer will be outside the “first screen”. See below for how to get around this.
Note 2. In Opera version 9.5 and higher, this example will not work when adding a doctype. Workaround options:
- add at least one floating block to the main container tag: This is the main block