Integrate docked footer - html

I am having a hard time with this. This is my code:
http://jsfiddle.net/HMsKa/30/
I am trying to integrate a docked footer for when there is little amounts of content. I am using this site for the code example of how to do this:
http://ryanfait.com/sticky-footer/
http://ryanfait.com/sticky-footer/layout.css
However, no matter what connotation I put this code into my site, it doesn't work. Could someone show me how I should integrate this with my existing code?

You have to check out your the html structure, look in the sticker-footer's html for example.
It has to be somewhat as below:
HTML:
<body>
<div class="wrapper">
<!-- your content -->
<div class="push"></div>
</div>
<div class="footer"></div>
</body>
As the css file says, I'll recreate it here:
* {
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 */
}
/*
Sticky Footer by Ryan Fait
http://ryanfait.com/
*/
A somewhat edit of your fiddle:
http://jsfiddle.net/HMsKa/36/
You need a .wrapper with a min-height: 100%.

Related

Sticky footer with header and content dropping below window

I have a layout where the footer is a sibling of the header and content, but the footer is dropping below the window height rather than "sticking" correctly at the bottom.
HTML
<div class="header">Header</div>
<div class="content">
Content
<div class="push"></div>
</div>
<div class="footer">Footer</div>
CSS
html, body {
height: 100%
}
.header, .footer, .push {
height: 75px;
}
.content {
margin-bottom: -75px;
min-height: 100%;
}
I've been looking over different options for sticky footer, and none seem to cover when the header and content are sibling elements with the footer. I'm working with a legacy layout, so I don't have the option of creating a wrapper container for the header and content. How can I get the footer to stay at the bottom without dropping below the window?
Since your header and footer are static heights you can do this:
min-height: calc(100% - 75px - 75px);
I keep them separate (the 75px), so that I know one is for footer and one is for header. And its easier to change in the future if one of the static heights changes.
Also, you will probably want to remove the margin from your body to get it to fit correctly and remove the negative margin you have on the footer.
html, body {
height: 100%;
margin: 0;
}
.header, .footer, .push {
height: 75px;
}
.content {
min-height: calc(100% - 75px - 75px);
}
<div class="header">Header</div>
<div class="content">
Content
<div class="push"></div>
</div>
<div class="footer">Footer</div>
Here is a fiddle of this solution.
add footer css with a separate class
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
}

Make footer sticky to bottom but not screen?

How do I make a footer (footer-tag) stick to the bottom of the screen, but not be sticky to the screen? If I'm on a 1080p monitor, the website has no scroll. When I try on 1366x768 the website becomes scrollable. I want the footer to be 100px below the content, because right now the footer is on top of the content. Here's my HTML structure:
<body>
<div id="container">
<div id="header"></div>
<div id="body"></div>
<footer></footer>
</div>
</body>
So I have a header, body, and footer inside a container. All the guides/tutorials I've seen, makes the footer stick to the screen. If it doesn't stick to the screen, it won't stick to the bottom. Whenever I open the Chrome Developer Tools bar/menu, the footer shoots back up, which I guess is because my body's height is 100%? But I'm not sure. Help appreciated! Thanks.
Quite easy: make html and body 100% height, your container (anything that has to be in the initial viewport) as well. Position the container relatively, the footer absolute, and put anything below.
Example on JSFiddle
Code
<style type="text/css">
html, body { height: 100%; }
#container { position: relative;
/* updated to support footer push */
min-height: 100%;
padding-bottom: 60px; /* must be the same as footer height */
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#below { height: 500px; } /* or no height, or whatever */
footer { position: absolute; bottom: 0; height: 60px; width: 100%; } /* as it's absolute, you should give it a specific height, or let it be as wide as its content */
</style>
<div id="container">
<footer>F-F-F-F-F-FOOTER!</footer>
</div>
<div id="below"></div>
Edit see the edited code above; min-height instead of height for the container to let it be able to stretch, but at least be as high as the screen. You'll have to add a bottom padding too, as high as the footer, to prevent the footer from overlapping your content. And also add box-sizing: border-box, otherwise the padding will add up to the height, resulting in the footer to be pushed down the initial viewport.
(For history's sake, here is the original fiddle)
footer { position : absolute; bottom : 0px; }
position : fixed ( When you want to stick any html element on screen and that will not move during scrolling )
position : absolute ( When it will show, it will be on the position that you specified, but later screen size and scrolling can change it's position )
Thanks ( Sorry for weak english )
:)
you could add some padding to the bottom of your page, and then use vh measurements:
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#header{
height:10vh;
}
#container {
background: red;
position:relative;
}
#body {
height: 70vh;
background: gray;
padding-bottom:20vh;
}
footer {
position: absolute;
bottom: 0;
height: 20vh;
width: 100%;
background: blue;
}
<body>
<div id="container">
<div id="header">header</div>
<div id="body">body</div>
<footer>footer</footer>
</div>
</body>

Footer doesn't stick at the bottom [duplicate]

This question already has answers here:
How do you get the footer to stay at the bottom of a Web page?
(32 answers)
Closed 8 years ago.
I've read a lot of articles and existing questions on stackoverflow. I've litteraly tried over 10 different pieces of code. It just doesn't work.
I've got a website, and I would like the footer to stick on the bottom no matter what. I mean, litteraly stick on the bottom. I do not want it to move with the height of the window of the browser. I want it to stay below all existing divs.
At the moment the footer is at the bottom of the page. But it moves with the height of the window of my browser. So, if I minimize my browser, the footer will move upwards with the height of the browser. I do not want that.
I've tried a lot, but it doesn't work. This is my current code:
body{
background-image: url('../images/bg.png');
background-repeat: repeat;
margin: 0px;
padding: 0px;
}
body, html{
height: 100%;
}
#body{
width: 1024px;
min-height: 100%;
margin: 0 auto;
}
#footer{
clear:both;
min-height: 150px;
width: 100%;
background-image: url('../images/footerbg.png');
background-repeat: repeat;
}
The body ID is the wrapper. The footer is outside the body wrapper
<body>
<div id="body">
<!-- HEADER -->
<div id="logo"></div>
<div id="menu">
<ul id="hmenu">
<!-- stuff -->
</ul>
</div>
<div id="page">
<!-- stuff -->
</div>
</div>
<div id="footer">
<!-- stuff -->
</div>
<div id="navigationbar"></div>
</body>
Edit:
The problem has to do with one of the divs inside the "body" div. It is being positioned using an absolute position. Is there any way to get the footer stickied properly using Ryan Fait's method, whilst using an absolute position?
Edit #2: I forgot to use "clear:both". Solved it
Ryan fait has a solution to this: http://ryanfait.com/sticky-footer/
I modified it slightly using SASS:
$footer-height: 250px; /* Set size of sticky footer in the variable: */
.main-wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto (-$footer-height); /* the bottom margin is the negative value of the footer's height */
}
.push {
clear: both;
height: $footer-height;
}
.footer-wrapper {
clear: both;
min-height: $footer-height;
background: #E7E7E7;
padding: 50px 0;
}
You could take out the variable for use with vanilla CSS.
Your HTML would look something like this:
<div class="main-wrapper">
<div class="wrapper"></div>
<div class="push"></div>
</div>
<div class="footer-wrapper"></div>
I think you should use this css for footer:
#footer{
position:fixed;
bottom:0;
background-image: url('../images/footerbg.png');
background-repeat: repeat;
}
like here.
All you need:
#footer{
position: fixed;
bottom: 0;
/* rest of your styles */
}
Also if you don't want content to be hidden behind the footer:
#body { /* your main div has an id of body, not to be mistaken for body tag */
padding-bottom: 150px /* height of footer */
}
Demo http://jsfiddle.net/2mzak87o/
Fix the div to the browser, then force it to have a 0 margin on the bottom and left.
#footer{
position: fixed;
bottom: 0;
left: 0;
clear:both;
min-height: 150px;
width: 100%;
background-image: url('../images/footerbg.png');
background-repeat: repeat;
}
If you want the div in the middle of the bottom, create a container with width:100% and then have the footer contain "margin: 0 auto"
try this :
#body {
width: 1024px;
min-height: 80%;
margin: 0 auto;
position: relative;
}
#footer {
clear: both;
min-height: 20%;
width: 100%;
background-image: url('../images/footerbg.png');
background-repeat: repeat;
}

Footer stick to bottom, Extends beyond page

Trying to make the footer stick to the bottom and the content become automatically centered in between the header and footer.
Currently using this technique: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
But my footer appears way below and creates a huge gap in between.
Website: Stingrayimages.ca
Edit: So i managed to get the footer to stick to the bottom. However, the footer is not at the bottom of the page, it leaves a little bit of a scroll. And when shrink the window, the footer doesnt stop where the content.
Also i cant get the content div to stay in the middle without messing everything up.
Your container div should wrap your Head div. I think you mistook Ryan's head area for what designers commonly refer to as the header of the page, when in fact in the example it's the head element of the html. The extra space on the bottom is likely equal to the height of your head div.
In the sticky footer, remember, the container wraps all body content but the footer.
If you are using the same technique as the link, you are missing position at the footer.
And still, with the example you linked, see the structure:
<style type="text/css">
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 */
}
</style>
<div class="wrapper">
<div class="header"></div>
<div class="push"></div>
</div>
<div class="footer"></div>
But i would rather go with something like this:
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
}
div#container {
position: relative;
margin: 0 auto;
height: auto !important;
height: 100%; /* IE6: min-height*/
min-height: 100%;
}
div#header {
}
div#content {
padding: 1em 1em 5em;
}
div#footer {
position: absolute;
width: 100%;
bottom: 0;
}
</style>
<div id="container">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>

How to align footer (div) to the bottom of the page? [duplicate]

This question already has answers here:
How do you get the footer to stay at the bottom of a Web page?
(32 answers)
Closed 8 years ago.
Can anyone explain how to align a footer div to the bottom of the page. From the examples I've seen, they all show how to make the div stay visible at the bottom, no matter where you've scrolled the page. Although I don't want it like that. I want it fixed at the bottom of the page, so it doesn't move. Appreciate the help!
UPDATE
My original answer is from a long time ago, and the links are broken; updating it so that it continues to be useful.
I'm including updated solutions inline, as well as a working examples on JSFiddle. Note: I'm relying on a CSS reset, though I'm not including those styles inline. Refer to normalize.css
Solution 1 - margin offset
https://jsfiddle.net/UnsungHero97/ur20fndv/2/
HTML
<div id="wrapper">
<div id="content">
<h1>Hello, World!</h1>
</div>
</div>
<footer id="footer">
<div id="footer-content">Sticky Footer</div>
</footer>
CSS
html, body {
margin: 0px;
padding: 0px;
min-height: 100%;
height: 100%;
}
#wrapper {
background-color: #e3f2fd;
min-height: 100%;
height: auto !important;
margin-bottom: -50px; /* the bottom margin is the negative value of the footer's total height */
}
#wrapper:after {
content: "";
display: block;
height: 50px; /* the footer's total height */
}
#content {
height: 100%;
}
#footer {
height: 50px; /* the footer's total height */
}
#footer-content {
background-color: #f3e5f5;
border: 1px solid #ab47bc;
height: 32px; /* height + top/bottom paddding + top/bottom border must add up to footer height */
padding: 8px;
}
Solution 2 - flexbox
https://jsfiddle.net/UnsungHero97/oqom5e5m/3/
HTML
<div id="content">
<h1>Hello, World!</h1>
</div>
<footer id="footer">Sticky Footer</footer>
CSS
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
min-height: 100%;
}
#content {
background-color: #e3f2fd;
flex: 1;
padding: 20px;
}
#footer {
background-color: #f3e5f5;
padding: 20px;
}
Here's some links with more detailed explanations and different approaches:
https://css-tricks.com/couple-takes-sticky-footer/
https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
ORIGINAL ANSWER
Is this what you mean?
http://ryanfait.com/sticky-footer/
This method uses only 15 lines of CSS and hardly any HTML markup. Even better, it's completely valid CSS, and it works in all major browsers. Internet Explorer 5 and up, Firefox, Safari, Opera and more.
This footer will stay at the bottom of the page permanently. This means that if the content is more than the height of the browser window, you will need to scroll down to see the footer... but if the content is less than the height of the browser window, the footer will stick to the bottom of the browser window instead of floating up in the middle of the page.
Let me know if you need help with the implementation.
This will make the div fixed at the bottom of the page but in case the page is long it will only be visible when you scroll down.
<style type="text/css">
#footer {
position : absolute;
bottom : 0;
height : 40px;
margin-top : 40px;
}
</style>
<div id="footer">I am footer</div>
The height and margin-top should be the same so that the footer doesnt show over the content.
Your title and comments imply that you weren't looking for a sticky footer (stuck to the bottom of the window as content scrolls below it). I assume you were looking for a footer that would be forced to the bottom of the window if the content does not fill the window, and push down to the bottom of the content if the content exceeds the window boundary.
You can accomplish this with the following.
&ltstyle>
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
&lt/style>
&ltdiv id="container">
&ltdiv id="header">header&lt/div>
&ltdiv id="body">body&lt/div>
&ltdiv id="footer">footer&lt/div>
&lt/div>
Source: How to keep footers at the bottom of the page
Use
<div style="position:fixed; bottom:0; height:auto; margin-top:40px;
width:100%; text-align:center">
I am footer
</div>
Footer will not go upwards
check this out, works on firefox and IE
<style>
html, body
{
height: 100%;
}
.content
{
min-height: 100%;
}
.footer
{
position: relative;
clear: both;
}
</style>
<body>
<div class="content">Page content
</div>
<div class="footer">this is my footer
</div>
</body>
A simple solution that i use, works from IE8+
Give min-height:100% on html so that if content is less then still page takes full view-port height and footer sticks at bottom of page. When content increases the footer shifts down with content and keep sticking to bottom.
JS fiddle working Demo: http://jsfiddle.net/3L3h64qo/2/
Css
html{
position:relative;
min-height: 100%;
}
/*Normalize html and body elements,this style is just good to have*/
html,body{
margin:0;
padding:0;
}
.pageContentWrapper{
margin-bottom:100px;/* Height of footer*/
}
.footer{
position: absolute;
bottom: 0;
left: 0;
right: 0;
height:100px;
background:#ccc;
}
Html
<html>
<body>
<div class="pageContentWrapper">
<!-- All the page content goes here-->
</div>
<div class="footer">
</div>
</body>
</html>
I am a newbie and these methods are not working for me. However, I tried a margin-top property in css and simply added the value of content pixels +5.
Example: my content layout had a height of 1000px so I put a margin-top value of 1005px in the footer css which gave me a 5px border and a footer that sits delightfully at the bottom of my site.
Probably an amateur way of doing it, but EFFECTIVE!!!