Sticky footer means that the footer part of the web page is always at the bottom of the browser window.
When the content of the web page is long enough to exceed the visible height of the browser, the footer will be pushed to the bottom of the web page along with the content;
But if the content of the web page is not long enough, the bottom footer will remain at the bottom of the browser window.
Method 1: Set the margin-bottom of the content part to a negative number
<p> <!-- content --> </p><p></p> <p>footer</p>
html, body { margin: 0; padding: 0; height: 100%; } .wrapper { min-height: 100%; margin-bottom: -50px; /* 等于footer的高度 */ } .footer, .push { height: 50px; }
This method requires additional space in the container Bit element (p.push).
The margin-bottom of p.wrapper needs to be the same as the -height value of p.footer. Note that it is a negative height.
Method 2: Set the margin-top of the footer to a negative number
Add a parent element outside the content and let the padding of the content part -Bottom is equal to the height of the footer.
<p> </p><p> <!-- content --> </p> <p>footer</p>
html, body { margin: 0; padding: 0; height: 100%; } .content { min-height: 100%; } .content-inside { padding: 20px; padding-bottom: 50px; } .footer { height: 50px; margin-top: -50px; }
Method 3: Use calc() to set the content height
<p> <!-- content --> </p> <p>footer</p>
.content { min-height: calc(100vh - 70px); } .footer { height: 50px; }
Assume here that there is 20px between p.content and p.footer Spacing, so 70px=50px+20px
Method 4: Use flexbox flexible box layout
The height of the footer in the above three methods is fixed. If the content of the footer Too much may break the layout.
<p> <!-- content --> </p> <p>footer</p>
html { height: 100%; } body { min-height: 100%; display: flex; flex-direction: column; } .content { flex: 1; }
Method Five: Use Grid Grid Layout
<p> <!-- content --> </p> <p>footer</p>
html { height: 100%; } body { min-height: 100%; display: grid; grid-template-rows: 1fr auto; } .footer { grid-row-start: 2; grid-row-end: 3; }
The above is the detailed content of Five ways to use CSS to put Footer at the bottom. For more information, please follow other related articles on the PHP Chinese website!

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

We lost Opera when they went Chrome in 2013. Same deal with Edge when it also went Chrome earlier this year. Mike Taylor called these changes a "Decreasingly

From trashy clickbait sites to the most august of publications, share buttons have long been ubiquitous across the web. And yet it is arguable that these

In this week's roundup, Apple gets into web components, how Instagram is insta-loading scripts, and some food for thought for self-hosting critical resources.

When I was looking through the documentation of git commands, I noticed that many of them had an option for . I initially thought that this was just a

Sounds kind of like a hard problem doesn't it? We often don't have product shots in thousands of colors, such that we can flip out the with . Nor do we

I like when websites have a dark mode option. Dark mode makes web pages easier for me to read and helps my eyes feel more relaxed. Many websites, including

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools