Sticky footer container that doesn't overlap other content - html

I have a sidenav which has a container with social media context that is meant to stick to the bottom of the sidenav which spans the entire view-port height like so:
sidenav {
height: 100%;
background: #007979;
left: 0;
position: fixed;
text-align:
width: 25rem;
}
The sidenav immediate child is a container which has it's position property set to relative to I can then assign a position property and value to the social media container to stick to the bottom, like so:
sidenav-inner {
position: relative;
height: 100%;
}
My issue is that if I set the social media containers position property to either absolute or relative, if the view-port height is adjusted slightly, the social media container overlaps the navigation list that is at the top, as it is positioned in correspondence to the sidenav-inner container.
Question
How do I position the social media container at the bottom of the sidenav, without using the position proeprty? Or how do I use the position property without it overlapping other content in the sidenav?
<nav class="sidenav">
<div class="sidenav-inner">
<div class="sidenav-header">
<div class="row">
<div class="col-md-12">
<img src="/">
</div>
</div>
</div>
<ul class="nav">
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
</ul>
<div class="side-nav-social">
<div>
//social media content
</div>
//more social media content
</div>
</div>
</nav>

You can easily solve this by defining .sidenav-inner as a flexbox and then having the header and footer not grow, but the ul grow to take up all the space. It will thus push the social media to the bottom of the box.
.sidenav {
height: 100%;
background: #007979;
left: 0;
position: fixed;
text-align:
width: 25rem;
}
.sidenav-inner {
position: relative;
height: 100%;
display: flex;
flex-direction: column;
}
.sidenav-header {
flex: 0 1 auto;
}
.sidenav-inner ul {
flex: 1 0 auto;
}
.side-nav-social {
flex: 0 1 auto;
}
https://jsfiddle.net/d2u85u4q/

You can do it like this:(be aware of margins)
html
<nav class="sidenav">
<div class="sidenav-inner">
<div class="sidenav-header">
<div class="row">
<div class="col-md-12">
header
<img src="/">
</div>
</div>
</div>
<ul class="nav sidenav-body">
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
</ul>
<div class="side-nav-social">
<div>
//social media content
</div>
//more social media content
</div>
</div>
</nav>
css:
.sidenav {
height: 250px;
background: #007979;
left: 0;
position: fixed;
width: 200px;
}
.sidenav-inner {
position: relative;
height: 90%;
}
.sidenav-header{
height:10%;
}
.sidenav-body{
overflow:auto;
height:70%;
}
.side-nav-social{
position:absolute;
bottom:0;
height:10%;
}
plnker code

Related

Child container top margin pulls down parent top margin

I've got a background image in a parent container that covers the full screen width.
I want a child container centered within the parent which will contain some text and have a semi-transparent background color.
No matter how I try to set the top margin of the child, the parent container's top margin moves along with the child's as if the two top edges are "glued" together. The parent's margin follows the child's.
How can I make the contained element (.content) move down while keeping the top edge of the image fixed to the top of the page?
Thanks!
BG image follows box's top margin
/* Header */
.hero {
background: url('../images/hero_laptop_2.jpg') no-repeat center center/cover;
height: 75vh;
position: relative;
color: #fff;
}
.hero .content {
border: solid black 1px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
width: 40%;
height: 60%;
padding: 20px;
z-index: 1;
margin-left: auto;
margin-right: auto;
margin-top: 200px;
}
<header class="hero">
<div id="navbar" class="navbar top">
<h1 class="logo">
<span class="text-primary"><i class="fas fa-desktop"></i> IT</span>-Simplified</h1>
<h1 id="navbar-phone">845-520-1115</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Testimonials</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="content">
<h1>Welcome to IT-Simplified</h1>
<p>We Provide COMPUTER SOLUTIONS... <br>Simply & Affordably.</p>
<p id="call-us">Call Us: 845-520-1115</p>
<!-- <i class="fas fa-chevron-right"></i> Testimonials -->
</div>
</header>
You need to add a position absolute or other positioning to the .hero .content class so that it will float on top of the background, independently of the parent container. Edit: In my solution below I have used position: relative;.
The z-index is irrelevant as the positioning take it out of the normal html flow context, so I removed it. Did a few other changes, take a look (use full screen, in the small snippet area below the content box doesn't display correctly).
Alternatively, you could try to make the .hero container display: flex; so you can position its children within it, but that doesn't seem to be practical here where you want the navigation on top and content below.
/* Header */
.hero {
background: url('https://www.esa.int/var/esa/storage/images/esa_multimedia/images/2017/11/autumn_fireball/17255671-1-eng-GB/Autumn_fireball.jpg') no-repeat center center/cover;
height: 100vh;
color: #fff;
}
.hero .content {
color: white;
position: relative;
border: solid yellow 1px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
width: 40%;
padding: 20px;
margin-left: auto;
margin-right: auto;
}
<header class="hero">
<div id="navbar" class="navbar top">
<h1 class="logo">
<span class="text-primary"><i class="fas fa-desktop"></i> IT</span>-Simplified</h1>
<h1 id="navbar-phone">845-520-1115</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Testimonials</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="content">
<h1>Welcome to IT-Simplified</h1>
<p>We Provide COMPUTER SOLUTIONS... <br>Simply & Affordably.</p>
<p id="call-us">Call Us: 845-520-1115</p>
<!-- <i class="fas fa-chevron-right"></i> Testimonials -->
</div>
</header>
Result:

absolute positioned element extends past sticky footer

I have a dynamic mega menu item when opened the height varies depending on the data, often the height will cause the element to extend past the sticky footer (also position absolute), which is not really what i want at all, is there any solution other than creating unnesesary content to fill the void?
html -
<nav class="menu__base drop-shadow--standard desktop" style="background:#034774;;">
<div class="container">
<ul class="menu__items menu__items--hidden">
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item open">
<span class="menu__sub-menu-item__title">Open nav item</span>
<span class="menu__item__hover-underline"></span>
<div class="menu__sub-menu-wrapper drop-shadow--standard" style="height: 732px; left: -2px; background-color: #034774;">
<div class="menu__sub-menu" style="margin-top: 0px;">
<div class="menu__mega-menu">
<div class="mega-menu-multi-race ">
<table class="mega-menu-multi-race__table">
content, lots and lots of content inside the open nav item
</table>
</div>
</div>
</div>
</div>
</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
</ul>
</div>
</nav>
<div class="container">
<p>
content inbetween
</p>
</div>
<div class="container">
<p>
more content
</p>
</div>
<div class="container">
<p>
more content.............
</p>
</div>
<footer class="container-fluid footer">
<section class="row">
<div class="container padding-all-10">
<div class="footer__info">
<div class="col-lg-6 col-md-6 col-xs-12 padding-lf-0">
<p class="margin-all-0">Sticky footer</p>
</div>
</div>
</div>
</section>
</footer>
css -
.menu__sub-menu-wrapper {
position: absolute;
top: 100%;
left: 0;
overflow: hidden;
margin-top: 2px;
left: -2px;
}
.menu__sub-menu {
left: 0;
top: 0;
}
.menu__item {
float: left;
position: relative;
border-right: solid 2px #053b5e;
font-weight: bold;
font-size: 17px;
list-style-type: none;
min-width: 100px;
text-align: center;
padding:5px;
}
.menu__items {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}
.footer {
width: 100%;
background:red;
font-size: 17px;
position: absolute;
bottom: 0;
}
link to fiddle - https://jsfiddle.net/2648daniel/wo3jxjb8/
Dan,
I have modified your fiddle a fair bit and have achieved what you are after. The menu no longer overlaps the footer and scales as required, based on a fixed height or whatever content within that block.
https://jsfiddle.net/2gLLkoks/7/
In summary I have used a combination of floating elements left/clearing the floats as appropriate. eg
.menu__sub-menu-wrapper {
float:left;
...
.menu__sub-menu {
float:left;
...
....
<div class="clear"></div>
</nav>
etc
I have also removed the absolute positioning from the elements and added a content wrapper which is absolutely positioned with a negative z-index so it appears under the sub menu.
.containerWrapper {position:absolute;top:50px;float:left;z-index:-1}
<div class="containerWrapper">
<div class="container">
<p>
more content...........
Hope this helps ;)

Bootstrap 3 100% Height DIV with Navbar and Sticky Footer

I have a layout using a fixed navbar and sticky footer. In the main body, I have a fluid container with a column aligned to the left. I want that column to vertically fill the main body (between the navbar and footer), however I can't get it to work. I've tried all the examples I can find, to no avail.
I've build this JSFiddle to show what I have so far.
This is what I'm hoping to achieve:
My HTML:
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 ">
<div class="main-content">
<h1>Hello world.</h1>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
Sticky footer based on Boostrap example.
</div>
</footer>
And my CSS:
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #999999;
}
/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */
body > .container-fluid {
padding-top: 50px;
}
.container-fluid .col-sm-6 {
padding: 0;
}
.navbar {
margin-bottom: 0;
}
.footer {
padding: 15px 0;
}
.main-content {
background: #efefef;
padding: 20px;
height: 100%;
min-height: 100%;
}
You can use height:calc(100vh - 110px); on the .main-content div. The 110px is the height of the footer + height of the header which is subtracted from the viewport height.
http://www.bootply.com/v8XITHB4fP

Position footer at the bottom of the page

I have a fairly complex layout that I am building, it relies on a is affected by height, and min-height's so the usual tricks to position the footer at the bottom aren't working.
Given my JSFiddle how can I position the footer at the bottom when the content is a lot or minimal?
Here is some of the css I am currently using:
body, html, #wrapper {
height: 100%;
min-height: 100%;
}
.header {
height: 30%;
background-color: aliceblue;
}
.main {
background-color: antiquewhite;
}
.main .content {
height: 2000px;
background-color: aquamarine;
padding-bottom:80px;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: beige;
}
If I understand your requirement correctly, you want the footer to sit at the bottom of the content box.
One solution is to make the content box position:relative and move the footer inside it, so that its position:absolute will bind it to the content box, and the bottom:0 will achieve the desired effect of having it sit against the bottom of said content box.
See http://jsfiddle.net/wn6uvske/5/.
HTML:
<div id="wrapper">
<div id="sidebar"></div>
<div id="body-content">
<div class="header">
<div class="navbar navbar-default" role="navigation">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li>Toggle Menu
</li>
</ul>
</div>
</div>
</div>
<div class="main">
<div class="content container">
<p>Content</p>
<div class="footer"> <!-- moved up into content container -->
<p>Footer</p>
</div>
</div>
</div>
</div>
</div>
(relevant) CSS:
.main .content {
height: 2000px;
background-color: aquamarine;
padding-bottom:80px;
position:relative;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: beige;
}
you can use the sticky footer trick. Wrap all of your content in a wrapper excluding the footer, set min-height:100% and margin: -(footer height) on said wrapper to keep it at the bottom:
FIDDLE
UPDATE
You can take the header section out and use CSS calc() to adjust the height:
NEW FIDDLE

Twitter Bootstrap 3 Sticky Footer

I have been using the twitter bootstrap framework for quite a while now and they recently updated to version 3!
I'm having trouble getting the sticky footer to stick to the bottom, I have used the starter template supplied by the twitter bootstrap website, but still no luck, any ideas?
just add the class navbar-fixed-bottom to your footer.
<div class="footer navbar-fixed-bottom">
Referring to the official Boostrap3 sticky footer example,
there is no need to add <div id="push"></div>, and the CSS is simpler.
The CSS used in the official example is:
/* Sticky footer styles
-------------------------------------------------- */
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto;
/* Negative indent footer by its height */
margin: 0 auto -60px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}
/* Set the fixed height of the footer here */
#footer {
height: 60px;
background-color: #f5f5f5;
}
and the essential HTML:
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<!-- Begin page content -->
<div class="container">
</div>
</div>
<div id="footer">
<div class="container">
</div>
</div>
</body>
You can find the link for this css in the sticky-footer example's source code.
<!-- Custom styles for this template -->
<link href="sticky-footer.css" rel="stylesheet">
Full URL :
https://getbootstrap.com/docs/3.4/examples/sticky-footer/sticky-footer.css
Here is a method that will add a sticky footer that doesn't require any additional CSS or Javascript other than what's already in Bootstrap and won't interfere with your current footer.
Example here: Easy Sticky Footer
Just copy and paste this directly into your code. No fuss no muss.
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<p class="navbar-text pull-left">© 2014 - Site Built By Mr. M.
<a href="http://tinyurl.com/tbvalid" target="_blank" >HTML 5 Validation</a>
</p>
<a href="http://youtu.be/zJahlKPCL9g" class="navbar-btn btn-danger btn pull-right">
<span class="glyphicon glyphicon-star"></span>  Subscribe on YouTube</a>
</div>
</div>
In addition to the CSS you just added, remember you need to add the push div before closing the wrap div
The basic structure for the HTML is
<div id="wrap">
page content here
<div id="push"></div>
</div> <!-- end wrap -->
<div id="footer">
footer content here
</div> <!-- end footer -->
Live view
Edit view
Here's the Sticky Footer simplified code as of today because they're always optimizing it and this is GOOD:
HTML
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer with fixed navbar</h1>
</div>
<p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
<p>Back to the default sticky footer minus the navbar.</p>
</div>
<footer>
<div class="container">
<p class="text-muted">Place sticky footer content here.</p>
</div>
</footer>
</body>
</html>
CSS
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
I'm a bit late on the subject but I came across this post as I've just been bitten by that question and finally found a really easy way to get over it, simply use a navbar with the navbar-fixed-bottom class enabled. For example:
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<span class="navbar-text">
Something useful
</span>
</div>
</div>
HTH
Here is my updated solution to this issue.
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
border-top: 1px solid #eee;
text-align: center;
}
.site-footer-links {
font-size: 12px;
line-height: 1.5;
color: #777;
padding-top: 20px;
display: block;
text-align: center;
float: center;
margin: 0;
list-style: none;
}
And use it like this:
<div class="footer">
<div class="site-footer">
<ul class="site-footer-links">
<li>© Zee and Company<span></span></li>
</ul>
</div>
</div>
Or
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
height: 142px;
}
.site-footer {
background: orange;
}
The sticky example doesn't work for me.
My solution:
#footer {
position: fixed;
bottom: 0;
width: 100%;
height: 3em;
}
The push div should go right after the wrap, NOT within.. just like this
<div id="wrap">
*content goes here*
</div>
<div id="push">
</div>
<div id="footer">
<div class="container credit">
</div>
<div class="container">
<p class="muted credit">© Your Page 2013</p>
</div>
</div>
Answered by the OP:
Add this to your CSS file.
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
/* Negative indent footer by it's height */
margin: 0 auto -60px;
}
/* Set the fixed height of the footer here */
#push,
#footer {
height: 60px;
}
#footer {
background-color: #eee;
}
/* Lastly, apply responsive CSS fixes as necessary */
#media (max-width: 767px) {
#footer {
margin-left: -20px;
margin-right: -20px;
padding-left: 20px;
padding-right: 20px;
}
}
I wanted a flexible sticky footer, which is why I came here. Top answers got me in the right direction.
The current (2 Oct 16) Bootstrap 3 css Sticky footer (Fixed size) looks like this:
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
As long as the footer has a fixed size, the body margin-bottom creates a push to allow a pocket for the footer to sit in. In this case, both are set to 60px. But if the footer is not fixed and exceeds 60px height, it will cover your page content.
Make Flexible: Delete the css body margin and footer height. Then add JavaScript to get the footer height and set the body marginBottom. That is done with the setfooter() function. Next add event listeners for when the page first loads and on resizing that run the setfooter. Note: If you footer has an accordion or anything else that triggers a size change, without a resize of window, you must call the setfooter() function again.
Run the snippet and then fullscreen to demo it.
function setfooter(){
var ht = document.getElementById("footer").scrollHeight;
document.body.style.marginBottom = ht + "px";
}
window.addEventListener('resize', function(){
setfooter();
}, true);
window.addEventListener('load', function(){
setfooter();
}, true);
html {
position: relative;
min-height: 100%;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* additional style for effect only */
text-align: center;
background-color: #333;
color: #fff;
}
body{
/* additional style for effect only not needed in bootstrap*/
padding:0;
margin: 0;
}
<div>
Page content
<br> <br>
line 3
<br> <br>
line 5
<br> <br>
line 7
</div>
<footer id="footer" class="footer">
<div class="container">
<p class="text-muted">Footer with a long text, so that resizing, to a smaller screen size, will cause the footer to grow taller. But the footer will not overflow onto the main page.</p>
</div>
</footer>
This has been solved by flexbox, once and forever:
https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/
The HTML
<body class="Site">
<header>…</header>
<main class="Site-content">…</main>
<footer>…</footer>
</body>
The CSS
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}
Simple js
if ($(document).height() <= $(window).height()) {
$("footer").addClass("navbar-fixed-bottom");
}
Update #1
$(window).on('resize', function() {
$('footer').toggleClass("navbar-fixed-bottom", $(document).height() <= $(window).height());
});
To Summarize all of these, just keep one thing in your mind that everything except footer should have min-height: 100% or little less.
I write my simplified sticky footer code with padding using LESS. This answer is probably off-topic because the question doesn't talk about padding, so if you're interested check this post for more details.
#footer-padding: 40px; // Set here the footer padding
#footer-inner-height: 150px; // Set here the footer height (without padding)
/* Calculates the overall footer height */
#footer-height: #footer-inner-height + #footer-padding*2;
html {
position: relative;
min-height: 100%;
}
body {
/* This avoids footer to overlap the page content */
margin-bottom: #footer-height;
}
footer{
/* Fix the footer on bottom and give it fixed height */
position: absolute;
bottom: 0;
width: 100%;
height: #footer-height;
padding: #footer-padding 0;
}
Based on Jek-fdrv's answer, I added an .on('resize', function() to make sure it works on every device and every resolution:
$(window).on('resize', function() {
if ($(document).height() <= $(window).height()) {
$('footer').addClass("navbar-fixed-bottom");
} else {
$('footer').removeClass("navbar-fixed-bottom");
}
});
The current version of bootstrap doesn't seem to work for this function anymore. If you download their sticky-footer-navbar example and place a large amount of content in the main body area the footer will get pushed down past the bottom of the viewport. It isn't sticky at all.
Here is a CSS based solution for a fully responsive variable-height sticky footer.
Advantage: footer allows variable height, as height no longer needs to be hard-coded in CSS.
body {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-moz-box-orient: vertical;
-moz-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100vh;
}
body > * {
-webkit-box-flex: 0;
-webkit-flex-grow: 0;
-moz-box-flex: 0;
-ms-flex-positive: 0;
flex-grow: 0;
}
body > nav + .container {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-moz-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
/* Reset CSS and some footer styling. Only needed on StackOverflow */
body {
padding: 50px 0 0;
margin: 0;
}
footer {
background-color: #f8f8f8;
padding: 15px 0 5px;
border-top: 1px solid #e7e7e7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Responsive sticky footer of any height</h1>
</div>
<p class="lead">You can have a sticky footer of any height using this CSS. It's also fully responsive, no JavaScript needed.</p>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">Place sticky footer content here.</p>
<p class="text-muted">And some more content.</p>
<p class="text-muted">And more...</p>
</div>
</footer>
And here is the un-prefixed SCSS (for gulp/grunt):
body {
display: flex;
flex-direction: column;
min-height: 100vh;
> * {
flex-grow: 0;
}
> nav + .container {
flex-grow: 1;
}
}
Just use flex! Make sure to use body and main in your HTML and it's one of the best solutions (unless you need IE9 support). It doesn't require a fixed height or similiar.
That's recommended for Materialize as well!
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
Html
<footer class="footer navbar-fixed-bottom">
<div class="container">
<span class="text-muted">Place sticky footer content here.</span>
</div>
</footer>
CSS
.footer {
position: fixed;
bottom: 0;
}
in Haml & Sass words all that is necessary:
Haml for app/view/layouts/application.html.haml
%html
%head
%body
Some body stuff
%footer
footer content
Sass for app/assets/stylesheets/application.css.sass
$footer-height: 110px
html
position: relative
min-height: 100%
body
margin-bottom: $footer-height
body > footer
position: absolute
bottom: 0
width: 100%
height: $footer-height
based on http://getbootstrap.com/examples/sticky-footer-navbar/
If yout want to use bootstrap build in classes for the footer. You should also write some javascript:
$(document).ready(function(){
$.fn.resize_footer();
$(window).resize(function() {
$.fn.resize_footer();
});
});
(function($) {
$.fn.resize_footer = function(){
$('body > .container-fluid').css('padding-bottom', $('body > footer').height());
};
});
It will prevent content overlapping by the fixed footer, and it will adjust the padding-bottom when the user changes the window/screen size.
In the script above I assumed that footer is placed directly inside the body tag like that:
<body>
... content of your page ...
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<div class="muted pull-right">
Something useful
</div>
... some other footer content ...
</div>
</div>
</body>
This is definitely not the best solution (because of the JS which could be avoided), but it works without any issues with overlapping, it is easy to implement and responsive (height is not hardcoded in CSS).
#myfooter{
height: 3em;
background-color: #f5f5f5;
text-align: center;
padding-top: 1em;
}
<footer>
<div class="footer">
<div class="container-fluid" id="myfooter">
<div class="row">
<div class="col-md-12">
<p class="copy">Copyright © Your words</p>
</div>
</div>
</div>
</div>
</footer>
Here is a very simple and clean sticky footer you can use in bootstrap. Totally Responsive!
HTML
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Brand" src="">
</a>
</div>
</div>
</nav>
<footer></footer>
</body>
</html>
CSS
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 100px;
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
background-color: red;
}
Example: CodePen Demo
Using flexbox is the easiest way I have found, from the guys of CSS-tricks. This is true sticky-footer, it works when the content is < 100% of the page and > 100% of the page:
<body>
<div class="content">
content
</div>
<footer></footer>
</body>
And CSS:
html {
height: 100%;
}
body {
min-height: 100%;
display: flex;
flex-direction: column;
}
.content {
flex: 1;
}
Note that this is bootstrap-agnostic, so it works with bootstrap and without it.
You can simply try adding a class on your footer navbar:
navbar-fixed-bottom
Then create a CSS named custom.css and body padding like this..
body { padding-bottom: 70px; }