Please note that I don't want it FIXED so bootstrap navbar-fixed-bottom does not solve my problem. I just want it to be always at the bottom of the content and also be responsive.
Any guide will be very much appreciated.
EDIT:
Sorry if I wasn't clear. What happens now is that when the content body does not have enough content. My footer moves up and then it leaves an empty space at the bottom.
Do you have example code you've been working on that is giving you a problem?
It seems like regular footer, if you don't want Fixed, you can update the style. What issue you are running into?
When it is the last thing in your HTML, it will always be on the bottom. Confusing question that needs a code example to understand what the problem is.
This (from the Bootstrap docs / examples) should be the accepted answer.
For me this does not work because my footer is rather tall. It's great if you just want a paragraph but mine has several columns - using this method, I end up with a margin under the footer when I go down to smaller sizes
Isnt this Bootstraps sticky footer solution? I dont think the OP meant this. For me, with a long page my footer appeared at the bottom of the screen but not at the bottom of the content (ie over the content). I had to change Position: absolute; to relative (in .footer class) for this to work.
This would be the correct answer if this topic did not have "not fixed" in the title...
this only works for footers with fixed size, I prefer the solution of Philip Walton as proposed by @ChristopherTan which is super slim and independent of the footer's height
S
Surjith S M
See the example below. This will position your Footer to stick to bottom if the page has less content and behave like a normal footer if the page has more content.
CSS
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: 100%;
margin: 0 auto -155px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 155px; /* .push must be the same height as .footer */
}
UPDATE: New version of Bootstrap demonstrates how to add sticky footer without adding a wrapper. Please see Jboy Flaga's Answer for more details.
Your links are broken
Why are there two height property definitions in wrapper?
@HardlyNoticeable one is min-width to force the wrapper even if the content is less.
Still wondering why there are two height properties definitions. You didn't answered @SurjithSM
@Erowlin That's an error. you dont needed two height properties. Only min-height will be enough, edited the answer.
C
Christopher Tan
use flexbox as you can use it at your disposal. The solution offered by bootstrap 4 still hunting overlap content in responsive layout, e.g: it will break in mobile view, i come across the most neat trick is to use flexbox solution demo shown at here:(https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/) this way we do not have to deal with fixed height issue which is an obsolete solution by now...this solution works for bootstrap 3 and 4 whichever you using.
footer{
width:100%;
min-height:100px;
background-color: #222; /* This color gets inverted color or you can add navbar inverse class in html */
}
NOTE: At the time of the posting for this question the above lines of code does not push the footer below the page content; but it will keep your footer from crawling midway up the page when there is little content on the page. For an example that does push the footer below the page content take a look here http://getbootstrap.com/examples/sticky-footer/
This is actually a bad solution, as the footer covers up the main content when they meet. You need to set the padding-bottom of the main content container equal to the height of the footer. And you need to do it dynamically on page load and resize events and also on footer DOMSubtreeModified.
e
eGlu
For people still struggling and the answered solution doesn't work quite as you want it to, here is the simplest solution I have found.
Wrap your main content and assign it a min view height. Adjust the 60 to whatever value your style needs.
I had the same issue as the one in question. After trying almost all highly ranked answers here, this was the only one that worked for me. And it worked in all sizes. Only change i made was "min-height:70vh". This will depend on your site's header and footer sizes.
This should be higher, works exactly like requested.
This worked for my needs. Just tweak the min-height value until you get the desired outcome.
Wonderful, this is the most simple and efficient solution to the footer placement problem!
This seems to be compatible with bootstrap, and hence should be the accepted answer, imho. It's not perfect, as a horizontal scrollbar seems to be appearing.
Florian: No horizontal scrollbar for me.
t
tao
For a pure CSS solution, scroll after the 2nd <hr>. The first one is the initial answer (given back in 2016)
The major flaw of the solutions above is they have a fixed height for the footer. And that just doesn't cut it in the real world, where people use a zillion number of devices and have this bad habit of rotating them when you least expect it and **Poof!** there goes your page content behind the footer!
In the real world, you need a function that calculates the height of the footer and dynamically adjusts the page content's padding-bottom to accommodate that height. And you need to run this tiny function on page load and resize events as well as on footer's DOMSubtreeModified (just in case your footer gets dynamically updated asynchronously or it contains animated elements that change size when interacted with).
Here's a proof of concept, using jQuery v3.0.0 and Bootstrap v4-alpha, but there is no reason why it shouldn't work on lower versions of each.
', {
text: "Human give me attention meow flop over sun bathe licks your face wake up wander around the house making large amounts of noise jump on top of your human's bed and fall asleep again. Throwup on your pillow sun bathe. The dog smells bad jump around on couch, meow constantly until given food, so nap all day, yet hiss at vacuum cleaner."
}))
.append($(''));
}
}); body {
min-height: 100vh;
position: relative;
}
footer {
background-color: rgba(0, 0, 0, .65);
color: white;
position: absolute;
bottom: 0;
width: 100%;
padding: 1.5rem;
display: block;
}
footer hr {
border-top: 1px solid rgba(0, 0, 0, .42);
border-bottom: 1px solid rgba(255, 255, 255, .21);
}
Feed that footer - not a game (yet!)
You will notice the body bottom padding is growing to accomodate the height of the footer as you feed it (so the page contents do not get covered by it).
Note: I used jQuery v3.0.0 and Bootstrap v4-alpha but there is no reason why it shouldn't work with lower versions of each.
Initially, I have posted this solution here but I realized it might help more people if posted under this question.
Note: I have purposefully wrapped the $([selector]).accomodateFooter() as a jQuery plugin, so it could be run on any DOM element, as in most layouts it is not the $('body')'s bottom-padding that needs adjusting, but some page wrapper element with position:relative (usually the immediate parent of the footer).
Later edit (3+ years after initial answer):
At this point I no longer consider acceptable using JavaScript for positioning a dynamic content footer at the bottom of the page. It can be achieved with CSS alone, using flexbox, lightning fast, cross-browser.
Here it is:
// Left this in so you could inject content into the footer and test it:
// (but it's no longer sizing the footer)
function addMoreContentToFooter() {
var f = $('footer');
f.append($('
', {
text: "Human give me attention meow flop over sun bathe licks your face wake up wander around the house making large amounts of noise jump on top of your human's bed and fall asleep again. Throwup on your pillow sun bathe. The dog smells bad jump around on couch, meow constantly until given food, so nap all day, yet hiss at vacuum cleaner."
}))
.append($(''));
} .wrapper {
min-height: 100vh;
padding-top: 54px;
display: flex;
flex-direction: column;
}
.wrapper>* {
flex-grow: 0;
}
.wrapper>main {
flex-grow: 1;
}
footer {
background-color: rgba(0, 0, 0, .65);
color: white;
width: 100%;
padding: 1.5rem;
}
footer hr {
border-top: 1px solid rgba(0, 0, 0, .42);
border-bottom: 1px solid rgba(255, 255, 255, .21);
}
Feed that footer - not a game (yet!)
Footer won't ever cover the body contents, as its not fixed. It's simply placed at the bottom when the page should be shorter using `min-height:100vh` on container and using flexbox to push it down.
Note: This example uses current latest versions of jQuery (3.4.1.slim) and Bootstrap (4.4.1) (unlike the one above).
V
Vin
This method uses minimal markup. Just put all your content in a .wrapper which has a padding-bottom and negative margin-bottom equal to the footer height (in my example 100px).
html, body {
height: 100%;
}
/* give the wrapper a padding-bottom and negative margin-bottom equal to the footer height */
.wrapper {
min-height: 100%;
height: auto;
margin: 0 auto -100px;
padding-bottom: 100px;
}
.footer {
height: 100px;
}
<body>
<div class="wrapper">
<p>Your website content here.</p>
</div>
<div class="footer">
<p>Copyright (c) 2014</p>
</div>
</body>
A
AnBisw
Or this
<footer class="navbar navbar-default navbar-fixed-bottom">
<p class="text-muted" align="center">This is a footer</p>
</footer>
The question specifically states that navbar-fixed-bottom is NOT what solves the problem.
B
Brian Edwards
None of these solutions exactly worked for me perfectly because I used navbar-inverse class in my footer. But I did get a solution that worked and Javascript-free. Used Chrome to aid in forming media queries. The height of the footer changes as the screen resizes so you have to pay attention to that and adjust accordingly. Your footer content (I set id="footer" to define my content) should use postion=absolute and bottom=0 to keep it at the bottom. Also width:100%. Here is my CSS with media queries. You'll have to adjust min-width and max-width and add or remove some elements:
#footer {
position: absolute;
color: #ffffff;
width: 100%;
bottom: 0;
}
@media only screen and (min-width:1px) and (max-width: 407px) {
body {
margin-bottom: 275px;
}
#footer {
height: 270px;
}
}
@media only screen and (min-width:408px) and (max-width: 768px) {
body {
margin-bottom: 245px;
}
#footer {
height: 240px;
}
}
@media only screen and (min-width:769px) {
body {
margin-bottom: 125px;
}
#footer {
height: 120px;
}
}