How to make Bootstrap sticky footer content go full page height? - html

I'm using a Boostrap sample to create a sticky footer for a web site using CSS, this all works fine the footer remains in place at the bottom of the page as the page is resized.
On a number of pages I have content that needs to be shown practically full page, barring the footer. The content section of the page therefore needs to be set to 100% height so its content in turn can be sized to full height.
Here's a JSFiddle that demonstrates the problem.
How can we make the green container div full height, so it touches the page top at the top and the top of the footer at the bottom?
Thanks!
<div id="wrap">
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer</h1>
</div>
<p class="lead">This is the sticky footer template taken from the Bootstrap web site.</p>
<p class="lead">How can we make this green .container div the full height of its parent #wrap div?</p>
</div>
<div id="push"></div>
</div>
<div id="footer">
<div class="container"></div>
</div>
#wrap .container {
background-color: lightgreen;
}
/* 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 !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: #f5f5f5;
}

I have the solution to your problem. I moved it from JSFiddle to codepen, because I like codepen better. No other reason.
http://cdpn.io/IJHxf
This is essentially where I got the answer from, and they explain it way better than I ever could.
http://v1.reinspire.net/blog/2005/10/11/css_vertical_stretch/
When you implement that answer though, what I found height: auto !important; is the culprit as to why it doesn't immediately work. Comment it out in your #wrap id to see it take full effect. The code pen has additional changes to really see what is going on. What you really need to make your original question work is
#wrap .container {
background-color: lightgreen;
min-height: 100%;
height: auto; /* this line takes care of "more than enough content problem" */
}
html, body {
height: 100%;
background-color: #dedede;
padding: 0;
margin: 0;
}
#wrap {
min-height: 100%;
/* height: auto !important; */
height: 100%;
margin: 0 auto -60px;
}
Actually, what you could do, and would make more sense is instead of commenting out the entire line height: auto !important; You could just take off the !imporant. For example
#wrap {
height: auto !important;
/* changed to */
height: auto;
}
I changed some colors around to make it more apparent what was really happening. You'll see that in the codepen. There are lots more comments in the code pen to see what I really did FYI.
Also, I found that your sticky footer gave my page a scroll bar because of the margin. For me, I got rid of the scroll bar with the code below.
margin: 0 auto -60px;
/* changed to */
margin: 0 auto -80px;

Related

I want footer show in the bottom page

When the user goes at the end of the page with the scrool, there he can see the footer. the footer must appear only at the end of bottom when the user go at the end. My code work when there are a lot of components in the page, so the footer does what I want. The problem is when the page has a little component the footer appears in this way:
My CSS are :
html{
min-height: 100% !important
position: relative !important
}
#footer{
background-color: #30373d
width: 100%
position: relative
height: auto
}
<div id="footer"></div>
Anyone can help m
Just add a wrapper around your content and give it a min-height:100vh; (or whatever height suits your actual layout) property like below.
If you want the footer to always appear at the bottom of the page, set it to positon:absolute;
body {
padding: 0;
margin: 0;
}
#wrapper {
min-height: 100vh;
}
footer {
min-height: 100px;
width: 100%;
background: black;
}
<div id='wrapper'>
very little content
</div>
<footer></footer>
Instead of working on the footer, work on the content. Given that your footer has a fixed dimension you can ensure the body content will always take at least the portion of the empty screen minus the footer size. For example you could specify your content min-height like this:
.content {
min-height: calc(100vh - footerDimension)
}

How to Avoid Scroll on Hashed A Tag Click with Fixed Height Content

I am currently encountering a tricky issue with hashed anchor links.
Here is a simple representation of my HTML code :
<div class="main-wrap">
<header></header>
<aside>
<nav>
<ul>
<li>Article1</li>
<li>Article2</li>
<li>Article3</li>
</ul>
</nav>
</aside>
<section>
<article id="article1">Content Here</article>
<article id="article2">Content Here</article>
<article id="article3">Content Here</article>
</section>
<footer></footer>
and the CSS :
body{overflow: scroll;}
.main-wrap{
overflow: hidden;
position: relative;
}
header{
position: relative;
z-index: 3;
height: 10vh;
}
aside{
position: fixed;
width: 22%;
height: 84vh; /* Equal to 100vh - (header + footer)vh */
top: 10vh;
left: 0;
bottom: 6vh;
}
section{
position: relative;
min-height: 84vh; /* Equal to 100vh - (header + footer)vh */
width: 78%;
left: 22%; /* Equal to aside width*/
}
footer{
position: relative;
z-index: 3;
height: 6vh;
}
I've created a sidebar menu with hashed links to have a scrolled navigation, wich as far as I've been is working. But when I'm clicking on the hashed anchors, all the elements are moving a little further top, including header and footer and are hidden by the overflow:hidden; property of the .main-wrap element. In addition when I go back to the non-hashed page, the issue is still running unless I reload it.
I can't find any clue of how I can fix it. Any ideas ?
Edited : I also use a reset.css that is setting the body and html padding and margin to 0.
Edited 2 :
I think I know what's going on. By clicking on an anchor-link the body is forced to scroll the .main-wrap div and that's why everything looks like it has moved top. In fact the overflow:hidden; property of .main-wrap has just moved a little further down and is hiding the wrong parts.
Default Browser Behavior:
When you click on a named or hashed link, the browser will try to scroll to have the target named link at the top of the view.
This is what is happening with your code too.
Another browser default:
Most browsers have default margins and padding greater than 0 for the HTML elements, including the html and body elements.
Your calculation of height: 84vh; /* Equal to 100vh - (header + footer)vh */ will cause the content height to be more than the viewport height if the html and the body tags have margins or paddings greater than 0 (and make it scrollable since you have body {overflow: scroll;}).
Solution:
Use a css reset, or in your case simply add this to your css
html,
body {
margin:0;
padding:0;
}
Demo https://jsfiddle.net/vkrhnf75/1/

How to Stop Sticky Footer at Content DIV

I've been tweaking my sticky footer in hopes of stopping it once it hits the #body div, but so far, I've been unsuccessful. In most cases, it doesn't usually cover the content, but on this page, it often does.
I would like to keep it stuck to the bottom of the window, if possible, but the only other solution I've been able to come up with is a fixed position. Any suggestions?
Well, you can apply a fixed position/sticky footer in a number of ways. One option is using only CSS, as Twitter Bootstraps Sticky Footer example. That is probably the simplest implementation.
/* The html and body elements cannot have any padding or margin. */
html,body { height: 100%; }
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -100px; /* Negative indent footer by it's height */
}
/* Set the fixed height of the footer here */
#push,#footer{ height:100px }
#footer {}
I am not sure about your desired result, but may be what you need is just like:
#footer {
position: fixed;
bottom: 0;
left:0;
right:0;
}
According to Ryan Fait you can use the following CSS in the document layout.css:
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em; /*-4em represents the height of the footer */
}
.footer, .push {
height: 4em;
}
As well as the following HTML markup, which is actually quite simple to implement and it works in all major browsers.
<html>
<head>
<link rel="stylesheet" href="layout.css" ... />
</head>
<body>
<div class="wrapper">
<p>Your website content here.</p>
<div class="push"></div>
</div>
<div class="footer">
<p>Website Footer Here.</p>
</div>
</body>
</html>
I've implemented it before and it works flawlessly for having a footer either stick to the bottom of the page, or at the bottom of your content, and it requires no jquery or javascript at all.
To respond to kurzweilguy's comment, the push makes it so that you can have the footer at 100% height, this would naturally extend the page to have a scroll bar, so to counter it you put a negative margin on it to bring it back up to make it fit on the bottom of the page. The footer that darcher references uses the same exact footer. It's a very nicely compiled footer!

100% Height and Width, CSS and Dynamic Content

I've looked around and haven't found QUITE what I'm looking for yet, so hopefully this question hasn't already been answered somewhere else!
Anyways, the layout in question can be found HERE. What I am trying to achieve is a fixed width left column, and fluid width content area. For the most part, it works just fine. However, when content expands beyond the browser window's height or width, the sections don't seem to expand like I would want. Notice how to grey bar at the top doesn't reach the right of the page content, and the height of the left column doesn't reach the bottom of the page content either.
Am I right in thinking this stems from the fact that setting something to 100% height or 100% width via CSS is static? i.e. Whatever the height/width of the browser window was when the CSS was called is saved and that's that?
If that's the case, maybe I need to look into some other methods of setting the height and widths of my elements. Any ideas? Also, note that the dummy content in the page is an image for now. I wanted to blur out names, etc. to keep data private.
THANKS FOR ALL OF YOUR HELP!!!
How about something like this...
The left column will only go as far as the right content though. If you want it to expand to the height of the viewport when there's not enough content to fill you'll need some javascript or you'll have to use a repeating background that fills the html
Demo: http://jsfiddle.net/wdm954/KyUfN/
<div id="wrapper">
<div id="left">left</div>
<div id="right">
<div id="content">
<div id="top">top</div>
content
</div>
</div>
</div>
CSS...
/* clearfix */
#wrapper:after, #right:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
font-size: 0;
}
#wrapper, #right {
display: inline-block;
}
#wrapper, #right {
display: block;
-height: 1px;
}
/* end clearfix */
#wrapper {
background-color: #000000;
}
#left {
float: left;
width: 300px;
color: #FFF;
}
#right {
margin-left: 300px;
}
#top {
height: 100px;
background-color: #DEDEDE;
border-bottom: 1px solid #B8B8B8;
}
#content {
background-color: #F4EBEB;
height: 600px;
width: 1200px;
}
If the background is the main problem, you can just style the wrapper. This is what I ended up doing for an unruly sidebar, as I didn't want to resort to JS and other solutions didn't work for me. In my case, the issue with the sidebar came because of jQuery tabs, that are part of the theme. When I switched to the tabs, the sidebar wouldn't extend to the full height, so the background wouldn't either.
HTML
<div id="wrapper" class="sidebar-right">
<div id="maincontent">
#content
</div>
<div id="sidebar-right">
#sidebar content
</div>
</div>
CSS
(this presumes 960 grid with 280px sidebar)
#wrapper.sidebar-right{
background: white url('images/bg.png');
background-repeat: repeat-y; /*repeats down the length of the page*/
background-position: 680px 0px; /*moves it into place*/
}
If you have different sidebars, or full-width layouts, change the background image/position and style accordingly. Hope that helps someone.

Help with Sticky Footer

I'm using a sticky footer for the first time with a site I putting together, however doesn't seem to be going as planned. There appears to be a large white space, and then a black area (this is the color of my footer) please see link http://c-hall.the-word.com/assignment/whatwedo.php I need the footer to butt up to the bottom of the last bit of content, in this case the text witch is yet to be styled. Please see code below - thanks for your help - Charley
CSS
/* sticky footer */
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -335px;
}
.footer, .push {
height: 335px;
background-color: #000;
}
#innerfooter {
width: 847px;
height: 335px;
position: relative;
background-image: url(../images/black_bar.png);
background-repeat: no-repeat;
text-align: left;
margin: 0 auto;
}
/* end sticky footer */
Try this out for size, this will stay at the bottom of the page if the content isn't long enough and prop up the bottom if the content reaches it http://ryanfait.com/sticky-footer/
Look at your html structure (Especially at the .wrapper div.). The placement of the div is wrong.
And read this link: http://www.cssstickyfooter.com/
You are always going to have this gap because the position of your footer is static so it's fixed to the bottom of your browser. This white gap is your body background width unused space. So fill it or eliminate it by less width of your page or any other approach you find appropriate !
The point is I'm not giving you a precise solution but it's more important to understand what you're doing not just applying tutorials.