There are so many devices and screen sizes that determine the size of the browser window that it is problematic to write code that satisfies all applications. Just squeezing the footer to the bottom of the page is acceptable in an ideal use case, but there are at least two situations where this is almost impossible to do.
Firstly, not only the screens of tablets and smartphones allow the movement of a physical screen on a virtual one. The physical window of visibility is smaller than the virtual screen window on which the physical can be moved. Secondly, if, how to press the footer to the bottom of the page (CSS rules) is more or less clear, then what about resizing the window of the browser itself?
Absolute and relative positioning
The decision to control all coordinates and sizes is not always the best, especially when displaying continuous content. The decision to put everything on the stream (a variant of line elements, not absolute blocks) when each next element is placed after the previous one and therefore there are no gaps or problems with displaying the footer: it is always at the end of the document, but not always “stuck” to the bottom browser window border.
The end of the stream is not the footer of the page. The footer may be at the bottom, but push it to the bottom of the browser window, CSS “will not allow”. At the same time, there are always two options for moving the lower border of the browser window: up and down - after the page has loaded into the browser. This is exactly the problem.
In most cases, a footer with CSS rule “bottom” with the following other rules for placing the page, header, content and footer can provide the desired solution.
But this solution will be simple. It will not take into account many situations.
The traditional position of the Internet programming style “I did not understand, did NOT” requires the developer to have a clear page structure, no calculations in the process, and the decision to press the footer to the bottom of the page can be left as such.
Classic footer solution
The easiest way to solve the problem with the footer, and indeed with the "site production", is to use CMS (site management systems). There is no problem how to press the footer to the bottom of the page, wordpress, drupal, magenta, 1c-bitrix and other CMS “know” and “do” themselves.
In most cases, the developer does so. Using some kind of control system, the programmer turns into a content manager and simply fills out templates, manages the placement of information, and sets up communications.
In the world of modern popular CMS, there is only one cardinal problem: the area of specific application, the interests of the customer and the qualifications of the contractor in very rare cases correspond to the mentality of the development team of any, the most advanced, CMS. Bugs, holes and problem areas are always found.
Footer Online Solution
All the bottlenecks in the programming of modern interesting sites without fail become the subject of discussions and solutions in the Internet environment. In the context of the final decision on the page, how to press the footer to the bottom of the page, 4 ways can be guaranteed and, only (!) By CSS rules alone.
Layout designers for some unreasonable and inexplicable reason decided that the problem of footer and the overall composition of the page is exclusively their prerogative.
The dynamics of HTML5 and CSS3 standards show that the syntax and semantics of hypertext are evolving. New ideas appear and old ones are updated. This is good, but the site is not HTML5 / CSS3 and not even a developer, coupled with the customer. This is a solution to a real problem in a real Internet space and field of application (services, products, ideas).
Browser window as a classic of the genre
The transition from text to graphics over thirty years made fundamental the concept of a window for any operating system. Both Windows, and Apple, and a friendly family of Unixoids all appeal to the window interface.
Window programming ideas and the separation of HTML elements into block ones with absolute and relative positions make the problem of pressing the footer to the bottom of the page extremely simple: you do not need to press the footer, but change the lower border of the browser window.
Which is easier, because the browser understands when information is placed in its bottom line (status bar):
This is not a decision to press the footer to the bottom of the page and this is not a footer, but in this example it is clear that the essence of the footer is to clarify the browser window with the desired design.
However, this fact is not related to the footer of the page, but only a feature of the browser. The status bar is not a footer.
JavaScript dynamic solution
After loading the page, the browser can work out the launch of the JavaScript script, which will specify the position of the page elements in accordance with the current size of the browser window. Naturally, this solution will definitely place the footer in the right place.
In this example, the response to the onload event is set by the GoPage () function, which determines the current coordinates of the scLogo div and positions it in the right place. The response of the browser window resizing event is set by the scfChange function.
Here, the coordinates of the desired element are recalculated in accordance with the resizing of the browser window. The problem of how to press the footer to the bottom of the page is resolved uniquely.
You can snap the desired element in relation to any border of the window. JavaScript is fast and the visitor will not notice how the elements were positioned: CSS rules or a JavaScript algorithm.
The result of this code when resizing the browser window:
Here, an element labeled Google will be accurately placed in the right place whenever the browser window is changed, but an element labeled isV will only be correctly displayed when the browser window is magnified down and the right slider is in the correct position.
The best solution for positioning elements
The era of static pages has long gone down in history. The application of AJAX technology, when page elements are filled with the necessary information depending on the visitor’s actions, is real. The idea when a page is formed on the fly is the future.
The best option for posting information on a page is not to show what the developer or site owner planned. If you look at the site through the eyes of a visitor who came for a specific purpose, it is quite reasonable to offer him every time exactly what he expects.
This is not such a strange idea as it might seem. But if the visitor worked on the site and the session ended in a certain position of the page, it would be reasonable to start the next session from this position.
It is not so difficult to remember the result of the work and the state of the visitor (page) at the time the session ended in cookies or in the database on the server. When the same visitor returns, you can return to the saved state, rather than creating the home page of the site.