What does this footer tag stand for. How to push the floating footer to the bottom of the page
Hello, dear readers of the blog site. We continue the topic of block layout, which was started and continued in the three previous articles. In principle, we have already managed to create both a two- and three-column site layout, and we even managed to consider the nuances of creating a fluid layout.
In addition, in the first articles on site layout (), some basic concepts of webmastering were considered, without understanding which it would be rather difficult to understand the nuances.
What problems did you have with our website layout?
Today we will try to solve one small problem that may arise with the layout we created earlier. Most often, this situation occurs when viewing it on large monitors (with high resolution) and when displaying a page with little information.
In this case, it may turn out that the footer will not be pressed to the bottom of the screen, but will be located almost in its middle in height, which in most cases will look ugly and unaesthetic.
Still, in my opinion, you need to press the footer to the very bottom of the site layout, and this will be especially true in the case when the page height is less than the height of the user's screen. Schematically, this can be represented as follows:
Those. the correct behavior of the footer for the case of a small amount of information on the page and big screen user will be:
To implement this, we need to carry out a number of manipulations with the code of our layout. Moreover, we will make changes not only to the style file CSS styling Style.css but also in Index.html containing html code and forming Div blocks. But first things first.
For example, we will use the three-column site layout we created earlier. In this case, Index.html will look like this:
And the following CSS properties were written in the Style.css file:
Body, html ( margin:0px; padding:0px; ) #maket ( width:800px; margin:0 auto; ) #header( background-color:#C0C000; ) #left( background-color:#00C0C0; width:200px ; float:left; ) #right( width:200px; background-color:#FFFF00; float:right; ) #content( background-color:#8080FF; margin-left:202px; margin-right:202px; ) #footer ( background-color:#FFC0FF; clear:both; )
Well, the layout itself looked something like this:
As you can see, the footer is not pressed to the bottom and, therefore, does not meet our requirements (it is always located under the lowest column), so we will have to make adjustments to the code. All the same can be done for the two-column layout, and for the fluid layout too. The method is universal.
How to push the footer to the bottom of the site layout
So we need to move the footer Div to the bottom of the screen. To do this, you first need to set the height of the entire page to one hundred percent (it will take up the entire screen). This will be necessary in order to then resize the main block with the layout also up to 100%.
All the content of the site page is placed in the opening and closing Body tags and therefore we need to add one more CSS property for the Body tag in Style.css that sets the height to 100%:
Body, html ( margin:0px; padding:0px; height: 100%; )
On appearance this will not be reflected in any way yet, but now the main blog can be stretched to the full height of the screen. Those. it was a kind of preparatory stage.
The main properties of CSS, if you wish, you can see. Now let's set the container Div that encloses our entire layout to a minimum height of 100%:
I also want to highlight it (div with id="maket"). To do this, we will set a frame for it using the corresponding Border () property:
The property border: solid 3px black allows you to set a solid border (solid) with a thickness of 3 pixels in black for this container. This will allow you to clearly see that the container with the layout is stretched to the full height of the screen, even with a small amount of information on the page:
Now we will need to take the footer block out of the general container and place it below, immediately after the general one. What will it give? And the fact that, finally, the footer in the layout deigns to go down, and will not, as before, cuddle up to its longest column. In this case, Index.html will look like this:
Please note that the footer block is no longer inside a common container (maket), and therefore its width is no longer controlled by the CSS properties set for maket in the Style.css file. The footer will be stretched across the width of the screen, but still it will be located at the bottom of the screen, immediately below the main block:
But again there is a problem, because in order to see the footer, now you have to scroll the screen in the browser (see the scroll bar in the above figure).
It turns out that this is because the main container (maket) occupies the entire screen size in height (this is determined by the min-height: 100% property), and the footer is located immediately behind it, and you will have to use scrolling to view it, which is not very convenient and functional. .
You can solve this problem by giving a negative padding to the footer container Div so that it moves up a distance equal to its height. In this case, the footer container will run over the main container and fit into the height of the browser screen (i.e., you will not need to use scrolling to view it).
But in order to set a negative indent from the top, you need to know this same footer height, but we don’t know it yet.
Therefore, first we set the height of the container containing the footer by setting the corresponding property in Style.css:
#footer( background-color:#FFC0FF; clear:both; height: 50px; )
And then we set for it a negative padding from above to a height equal to its height:
This will allow the footer to rise up exactly to its own height and thus fit into the browser screen (now we can remove the border: solid 3px black CSS property from the maket rule so that the thickness of the border does not prevent our entire layout, along with the footer, from fitting into the screen in height) :
As you can see, now the scrollbar in the browser does not appear and our entire three-column block-based site layout fits on one screen (in case of a small amount of information on the page) and has a footer located at the very bottom. Which is exactly what we needed to do.
We insert the spacer and fight with Internet Explorer
But there is a problem, which will appear only when there is more information on the layout page and this situation may turn out:
It turns out that a situation may arise when the information in one of the columns of the layout will run into the footer, which will not look nice. This is due to the notorious negative padding we set for it, which helped elevate our footer into the main layout container.
Those. it turns out that at the bottom of the screen there are two blocks overlapping each other in the basement area.
The solution to this problem is to add a new empty container Div (called spacers) into the main container of our layout (maket), in the place where the block with the footer was located earlier.
By setting the height of this new container to the height of the footer, we can avoid the information from the main container colliding with the footer block. Let's give this container an ID () called Rasporka and as a result Index.html of our three-column layout will look like this:
And in Style.css we write for this ( , which sets the height of this spacer container equal to the height of the basement:
#rasporka ( height: 50px; )
As a result, the footer will be pressed from the bottom not to the information contained in the main container (for example, the text in the highest column), but to an area equal in height to the footer with a spacer container that does not contain any information.
In this way, we avoid collisions and distortions in our three-column layout. Everything will be clear and beautiful (decency and nobility):
As I mentioned above, the width of the footer should now be set separately, because. this container is no longer part of the main one. To do this, add to css file additional properties for the Footer, allowing you to set its width and align it horizontally in the middle of the screen.
It makes sense to set the width equal to the width of the entire layout using the Width property, and horizontal alignment can be done in the same way as we did for the entire layout on a block layout.
Thus, we will need to add additional properties for the Footer ID:
#footer( background-color:#FFC0FF; clear:both; height: 20px; margin-top:-20px; width:800px; margin-left: auto; margin-right: auto; )
Using the width:800px property, the width is set to 800 pixels, and using the two properties margin-left: auto and margin-right: auto , the margin-left setting to the left and right of the footer is automatically set, as a result of which these margins will be equal and our hero will align to middle:
Well, it seems there is nothing more to improve, but there it was. As always, our favorite browser Internet Explorer 6 does not understand something from the CSS properties we use. In this browser (and probably in some other old ones too), despite all our efforts, the footer will not be pressed to the bottom, but will still stick to the highest column of the site layout.
This is all because ( doesn't understand the min-height: 100% property we used to set the main box's minimum height to be the same as the screen height.
Therefore, to solve this problem, we will have to apply the so-called hack, which allows us to explain (on the fingers) to old browsers what to do. Before css list properties for maket you will need to insert the following combination:
* html #make ( height: 100%; )
This rule will only apply to Internet browser Explorer 6, the rest will not take it into account and execute it.
So, the final look of Style.css with the footer pressed to the bottom of the screen will be as follows:
Body, html ( margin:0px; padding:0px; height: 100%; ) * html #maket ( height: 100%; ) #maket ( width:800px; margin:0 auto; min-height: 100%; ) # header( background-color:#C0C000; ) #left( background-color:#00C0C0; width:200px; float:left; ) #right( width:200px; background-color:#FFFF00; float:right; ) #content ( background-color:#8080FF; margin-left:202px; margin-right:202px; ) #footer( background-color:#FFC0FF; clear:both; height: 50px; margin-top:-50px; width:800px; margin-left: auto; margin-right: auto; ) #rasporka ( height: 50px; )
Well, the final form of Index.html was given a little higher. That's it, this series of articles devoted to the block layout of 2 and 3 column fixed and rubber site layouts can be considered completed.
You can also watch the video "Working with Html div tag":
Good luck to you! See you soon on the blog pages site
You may be interested
Block layout - We create two-column, three-column and fluid layouts for the site
DiV layout - Create blocks for two column layout in HTML, determine their sizes and set positioning in CSS
Often when installing buttons, banners, etc. there is a need html inserts, css and JavaScript codes in the body of the body and head tags. Incorrect manual execution of this operation can damage the site and even completely disrupt its performance.
To automate this process, a wonderful plugin has been created, go to the settings in the admin panel and work with pleasure. It is easy to use and has the following features:
To enlarge an image, click on it with the mouse button. Click again to zoom out.
1. Page Head and Footer. Adding code to home page site.
Code to be added on HEAD section of the home (code to be inserted into the header of the home (main) page). Allows you to insert meta tags, codes for advertising banners, buttons, etc. in the tag body
. More often this is an invisible part of the code for the absence of a visual display on the site. The result of the work of the visible part of the code will appear above the header on the main page.Code to be added on HEAD section of every page (code to be inserted in the header of each page). Adding code to the tag body
to the HEAD section. The result of the visible part of the code will appear above the header on all pages, including the main one.Code to be added before the end of the page (code to be inserted at the end (footer) of the page). Add code to the footer on all pages before the closing tag