CSS to make HTML page footer stay at bottom of the page with a minimum height, but not overlap the page
A simple method is to make the body 100%
of your page, with a min-height
of 100%
too. This works fine if the height of your footer does not change.
Give the footer a negative margin-top:
footer {
clear: both;
position: relative;
height: 200px;
margin-top: -200px;
}
How to set footer at bottom of a page?
Keep footer ideally at page bottom (unless pushed by content)
- Use a parent element (i.e: body) set to
display: flex;
- Use a main element set to Flex Grow set to
1
/* QuickReset */ * {margin: 0; box-sizing: border-box;}
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
min-height: 100%;
}
.layout-main {
flex-grow: 1;
}
.layout-footer {
background: gold;
}
<main class="layout-main">
Some short Main content
</main>
<footer class="layout-footer">
I will stay ideally in the bottom when not enough content in Main
</footer>
How do you get the footer to stay at the bottom of a Web page?
To get a sticky footer:
Have a
<div>
withclass="wrapper"
for your content.Right before the closing
</div>
of thewrapper
place the<div class="push"></div>
.Right after the closing
</div>
of thewrapper
place the<div class="footer"></div>
.
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 142px; /* .push must be the same height as .footer */
}
How to keep footer at bottom of screen
What you’re looking for is the CSS Sticky Footer.
* { margin: 0; padding: 0;}
html,body { height: 100%;}
#wrap { min-height: 100%;}
#main { overflow: auto; padding-bottom: 180px; /* must be same height as the footer */}
#footer { position: relative; margin-top: -180px; /* negative value of footer height */ height: 180px; clear: both; background-color: red;}
/* Opera Fix thanks to Maleika (Kohoutec) */
body:before { content: ""; height: 100%; float: left; width: 0; margin-top: -32767px; /* thank you Erik J - negate effect of float*/}
<div id="wrap"> <div id="main"></div></div>
<div id="footer"></div>
CSS to make HTML page footer stay at bottom of the page with a minimum height, but not overlap the page
A simple method is to make the body 100%
of your page, with a min-height
of 100%
too. This works fine if the height of your footer does not change.
Give the footer a negative margin-top:
footer {
clear: both;
position: relative;
height: 200px;
margin-top: -200px;
}
Related Topics
What Is the Way to Add Horizontal Scroll on Material-Ui Table With Many Columns
Family Tree With Pure HTML and CSS (Or With Minimal Js)
How to Use HTML to Print Header and Footer on Every Printed Page of a Document
Stretch Child Div Height to Fill Parent That Has Dynamic Height
How to Suppress Spacing Between Paragraphs of the Same CSS Class
How to Style a Select Tag'S Option Element
Css to Select/Style First Word
Difference Between Normalize.Css and Reset Css
Position Deeply Nested Elements in a Higher Level Grid Container
Flex-Box: Align Last Row to Grid
How to Force Webkit to Redraw/Repaint to Propagate Style Changes
What Is the Default Padding And/Or Margin For a P Element (Reset Css)
Bootstrap Dropdown Sub Menu Missing
Select Every Nth Element in Css
::Slotted CSS Selector For Nested Children in Shadowdom Slot