Table of Contents
What is the layout of Sticky footer?
Illustration
Implementation method
Negative margin layout method
flex layout method
Summary
Home Web Front-end HTML Tutorial What is the layout of Sticky footer?

What is the layout of Sticky footer?

Jun 24, 2017 pm 02:18 PM
sticky layout use

Most of the website pages we see will divide a page into a header block, a content block and a footer block. When the header block and content block have less content, Footers can be anchored to the bottom of the screen rather than following the flow of the document. When there is a lot of content on the page, the footer can automatically expand with the flow of the document and be displayed at the bottom of the page. This is the Sticky footer layout.

Illustration

  • When the content is small, the normal document flow effect is as follows

What is the layout of Sticky footer?

In normal document flow, when the page content is small, the footer part is not fixed at the bottom of the window. In this case, the Stickyfooter layout must be used.

  • The layout effect of Sticky footer is as shown below

Sticky footer布局.jpg

This is in line with our expected effect, as you can see The application scenarios of sticky footer layout are still very wide.

Implementation method

Negative margin layout method

html code:

1

<div class="wrapper clearfix"><div class="content"// 这里是页面内容</div>  </div><div class="footer">// 这里是footer的内容</div>

Copy after login

css code:

1

.wrapper {min-height: 100%;}.wrapper .content{padding-bottom: 50px; /* footer区块的高度 */}.footer {position: relative;margin-top: -50px;  /* 使footer区块正好处于content的padding-bottom位置 */height: 50px;clear: both;}.clearfix::after {display: block;content: ".";height: 0;clear: both;visibility: hidden;}

Copy after login

Note: The padding-bottom of the content element, the height of the footer element and the footer element margin-topThe value must be consistent.

This negative margin layout method is the most compatible layout scheme. All major browsers are perfectly compatible and suitable for various scenarios. However, the prerequisite for using this method is that Know the height of the footer element, and the structure is relatively complex.

flex layout method

html code:

1

<div class="wrapper"><div class="content">这里是主要内容</div><div class="footer">这是页脚区块</div>  </div>

Copy after login

css code:

1

.wrapper {display: flex;flex-direction: column;min-height: 100vh;}.content {flex: 1;}.footer {flex: 0;}

Copy after login

This layout The method has a simple structure and a small amount of code, and is also a recommended layout method.

Summary

Sticky footer layout is a very common page layout form, and there are many ways to implement it. The above two methods are the most commonly used and can basically meet all application scenarios.

The above is the detailed content of What is the layout of Sticky footer?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Windows 11: The easy way to import and export start layouts Windows 11: The easy way to import and export start layouts Aug 22, 2023 am 10:13 AM

Windows 11: The easy way to import and export start layouts

How to save desktop icon position layout in Windows 11 How to save desktop icon position layout in Windows 11 Aug 23, 2023 pm 09:53 PM

How to save desktop icon position layout in Windows 11

Guide to solving misalignment of WordPress web pages Guide to solving misalignment of WordPress web pages Mar 05, 2024 pm 01:12 PM

Guide to solving misalignment of WordPress web pages

Which computer should Geographic Information Science majors choose? Which computer should Geographic Information Science majors choose? Jan 13, 2024 am 08:00 AM

Which computer should Geographic Information Science majors choose?

How to create a responsive carousel layout using HTML and CSS How to create a responsive carousel layout using HTML and CSS Oct 20, 2023 pm 04:24 PM

How to create a responsive carousel layout using HTML and CSS

Flexible application skills of position attribute in H5 Flexible application skills of position attribute in H5 Dec 27, 2023 pm 01:05 PM

Flexible application skills of position attribute in H5

Robot ETF (562500) may usher in a good layout opportunity because it has pulled back for 3 consecutive days! Robot ETF (562500) may usher in a good layout opportunity because it has pulled back for 3 consecutive days! Dec 01, 2023 pm 04:01 PM

Robot ETF (562500) may usher in a good layout opportunity because it has pulled back for 3 consecutive days!

Introducing the window arrangement method in win7 Introducing the window arrangement method in win7 Dec 26, 2023 pm 04:37 PM

Introducing the window arrangement method in win7

See all articles