What is a sticky footer layout? Our common web page layout is generally divided into the header part, the content part and the footer part. When the content in the header and content areas is small, the footer area is not arranged along with the content area but is always displayed at the bottom of the screen. When the content area contains a lot of content, the footer can expand with the document flow and always appear at the bottom of the page. This is the legendary Sticky footer layout. Isn’t it easy to understand? It’s okay if you don’t understand. Let me give you a simple example. Generally speaking, on a mobile page, when the content height does not fill up one screen, the footer is close to the bottom of the screen; when the content height exceeds one screen, the footer follows closely. Method 1: flex box layout
Click hard to see the demo: Flexbox layout implements sticky footer <div class="container"> <div class="content">Content</div> <div class="footer">Footer</div> </div> body { margin: 0; } .container { display: flex; flex-direction: column; min-height: 100vh; } .content { flex: 1; /*Not required*/ width: 100%; height: 300px; line-height: 300px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /*Not required*/ } .footer { height: 60px; /*Not required*/ width: 100%; line-height: 60px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /*Not required*/ } Method 2: padding-bottom + negative margin-top
Click hard to see the demo: padding-bottom + negative margin-top to achieve sticky footer <div class="wrapper"> <div class="content">Content</div> </div> <div class="footer">Footer</div> body { margin: 0; } .wrapper { width: 100%; min-height: 100vh; } .content { /*padding-bottom should be equal to the height of footer*/ padding-bottom: 60px; /*Not required*/ width: 100%; height: 400px; line-height: 400px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /*Not required*/ } .footer { /*margin-top should be equal to the negative value of footer height*/ margin-top: -60px; height: 60px; /*Not required*/ width: 100%; line-height: 60px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /*Not required*/ } Tip: The part between the two This is the end of this article about the implementation of the classic CSS sticky footer layout. For more relevant CSS sticky footer content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: DD DT DL tag usage examples
>>: Summary of changes in the use of axios in vue3 study notes
In the UI cutting process, the page is often comp...
FireFox is a commonly used browser with many exte...
1. Form 1. The role of the form HTML forms are us...
background All of the company's servers are p...
The reason for writing such an article is that on...
Data backup and restore part 3, details are as fo...
It is too troublesome to find the installation tu...
Enable remote access rights for mysql By default,...
This article describes the example of MySQL sched...
This article shares the specific code for the WeC...
This is the effect to be achieved: You can see th...
1. Use ansible's playbook to automatically in...
The value of the background property in CSS backg...
bgcolor="text color" background="ba...
Detailed explanation of Linux LVM logical volume ...