I've been using http://ryanfait.com/sticky-footer/ and it works great until you need a margin/padding at the top of the page. The design I'm working with has a patterned body and all the page content is in a white box that starts 15px from the top. I still need a footer that sticks to the bottom cross browser. Any ideas?
UPDATE:
Thanks for all the ideas but noting works perfectly. Adding a margin to a sub element of the wrapper puts in an un-nessary scrollbar: Working example: http://jsfiddle.net/cronoklee/p2cPD/
If you're open to scrapping the sticky footer you've been using, here's how I would go about making one from scratch.
HTML
<div class="wrapper">
<div class="content">
... Your Content Here ...
</div>
</div>
<div class="footer">
... Your Footer Here ...
</div>
CSS
.wrapper {
background: #eee;
padding: 15px 0 100px;
}
.content {
background: #fff;
}
.footer {
background: #ccc;
bottom: 0;
height: 100px;
left: 0;
position: fixed;
right: 0;
}
That should work cross browser. The only nuance about this to be aware of is that position: fixed doesn't work in IE 6. Any improvements are welcome :)
Could you apply a margin-top to the body?
body{
margin-top:15px;
}
This works with firebug on the page you linked to.
A solution without adding a scrollbar. Make these adjustments:
.header{
height:168px; /*15px + image height*/
image-position:bottom;
margin-bottom:37px;
}
.download{
top:175px;
}
Well, I just found this thread since I have had the same problem ten minutes ago and I'd like to share my solution to the problem with "unnecessary scrollbar caused by vertically-down-shifted footer caused by my header-div with margin-top: 20px, because I just want it to be 20px from the very top of the page", which I came up in the meantime.
Just change your .content{margin-top:15px;} to .content{padding-top:15px;} and it should work. The scrollbar should disappear and the content has it's distance from the top.
As seen here: http://jsfiddle.net/p2cPD/24/
Yes - it will expand the content-div's background, but if you don't want it there it can be solved by using some transparent png of some sort or whatever.
Also, according to the http://ryanfait.com the <div class="push"></div> thing should be at the end inside wrapper-div and after content-div, not inside content-div.
Related
I'm trying to publish my portfolio site and I'm almost done, but I'm having a problem with my sticky footer covering content when there's enough content to need to scroll down. I've tried messing with padding and margins all afternoon but I still can't seem to get it the way I want it.
Basic HTML skeleton:
<body>
<header>
<nav>
</nav>
</header>
<div id="wrapper">
<section>
<ul id="gallery">
<li>
</li>
</ul>
</section>
</div>
<footer>
</footer>
</body>
Footer:
footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
font-size: 0.425em;
text-align: center;
clear: both;
padding-top: 10px;
color: #ccc;
border-top: 5px solid #cc7a00;
}
Any help would be appreciated!
After inspecting the HTML on the page you mentioned above, it looks like you might have some un-cleared floats. You can read more about floats and why they need to be cleared here: https://css-tricks.com/the-how-and-why-of-clearing-floats/.
The short answer is the wrapper isn't increasing its dimensions to encompass its children because of those floats. If you inspect your page using dev tools, you can see the wrapper essentially has no height. That means adding a margin to it isn't really going to do anything.
If you were trying to add margin and padding to the footer itself, that won't work either since you're using position:fixed. You've told it to stick to the bottom of the page and not affect the other content on the page. It wouldn't make sense to let content scroll underneath the footer and still let it have a margin that pushes away other content, right?
There are a bunch of ways to solve this problem. Here's one-
To solve your float problem, you can use the overflow:auto trick:
#wrapper {
overflow:auto;
}
Read more about overflow:auto and floats here: Why does 'overflow: auto' clear floats? And why are clear floats needed? Please note this doesn't really clear the floats but the effect is that the wrapper height will respond to its children which is what we really need here.
Then adding some extra margin on the bottom of the wrapper div to account for the height of the footer should work:
#wrapper {
overflow:auto;
margin: 0 auto 100px auto;
}
The margin property above sets the margin-top to 0px, margin-right to auto, margin-bottom to 100px, and margin -left to auto. I suggested this becuase the page you linked to already had margin: 0 auto; (margin top and bottom 0, and margin left and right auto) to center the wrapper in the page. Otherwise, if you only needed to adjust the space at the bottom you would use margin-bottom: 100px;
Try adding
padding-bottom: 97px;
to your HTML element
EDIT
html { padding-bottom: 97px; }
97px is the height of your footer.
On your <div id="wrapper"> add to the CSS: bottom : someValueMatchingTheFooterHeight;
Okay, so i need a slider which is in a normal page to span across the whole screen.
The wrapper and all other elements is 960px max-width so thats how far the slider goes.
If i change these, the whole site will become messed up.
Im using Wordpress 3.5 with Twentytwelve theme as parent.
SLIDER: http://rocketplugins.com/wordpress-slider-plugin/
This is the only code i use in the post. So i guess i need to make the post wider?
[slider id='32' name='']
Not too sure about the product that your link explains but you will need to edit your page template.
There will be a content div (the one with max-width set). your new div, the one for the new slider, needs to be above it. I made a page layout fiddle just for you.
HTML
<div class="newdiv">Slider here</div>
<div class="content">
<p>Your WordPress post stuff here</p>
</div>
CSS
.content{max-width:960px; height: 800px; background: #D3D3D3; margin: 0 auto;}
.newdiv{width:100%; height:200px; background:#BADA55;}
Solved by
<div id="slider">[slider id='32' name='']</div>
and
#slider {
position: absolute;
left: 0;
right: 0;
height: 563px;
display: block;
}
Its not the best solution. But it works!
EDIT 2:
There was an error in my code that was causing the footer to not stick to the bottom of the page. My code looked something like this:
<div id="footer">
<div id="copyright-bg" class="container">
<div class="row">
<div class="twelvecol">
<p class="copyright-text">Lorum Ipsum</p>
</div>
</div>
</div>
</div>
I removed <div id="footer"> and moved those CSS properties to id="copyright-bg" and it then began to stick properly to the bottom. But now there has risen another issue! I now have unnecessary scroll bars! Here is a Fiddle that has the barest of code to attempt to figure what is going on. I thought it could be the gradient but when I changed the code to a solid background the scroll bars still appeared.
Note: I have tested in Chrome and Firefox.
EDIT:
I have attempted to use the CSS Sticky Footer per instructions on the website.
I assume there is a conflict in my CSS(?) here is a Fiddle of the page.
I have also attempted what this website suggested and while it technically works it creates scrollbars! I would like to avoid that if possible.
Original Question
I am working on a page and if the page does not have much content (IE no scroll bars for the page) I am left with a black bar below my copyright container.
Here is a screenshot:
Note: Where you see the word Done is the bottom of my browser, an arrow is pointing to the black bar.
I have attempted a few things to remove the bar. When I add height: 100%; to the body tag it will take my background gradient and it will reach to the bottom of the page but again that doesn't look good. I then attempted to add height: 100% to the copyright container. That caused the gray area to stretch way down and cause excessive empty space and scrollbars. I have attempted to position the element absolutely but that causes several other issues and would prefer to avoid positioning absolutely.
How do I remove the black bar? (Preferably with just CSS but will accept an answer that uses jQuery/Javascript)
CODE:
HTML:
<!-- Body Content Is Here -->
<div id="copyright-bg" class="container">
<div class="row">
<div class="twelvecol">
<p class="copyright-text">Ipsum</p>
</div>
</div>
</div>
CSS:
html, body{
font-size:1em;
font-family: "ff-dagny-web-pro", Helvetica, Arial, sans-serif;
line-height:1.438em;
color:#222;
margin: 0;
padding: 0;
text-align: justify;
background: linear-gradient(to bottom, rgba(0,0,0,1) 25%,rgba(209,209,209,1) 100%);
/* Vendor Specific Background Gradients... */
}
#copyright-bg{
margin-top:1.875em;
background: none repeat scroll 0 0 #666666;
border-top: 5px solid #E31836;
padding:1.250em;
}
.container {
padding-left: 20px;
padding-right: 20px;
}
.row {
width: 100%;
max-width: 1140px;
min-width: 755px;
margin: 0 auto;
overflow: hidden;
}
.row .twelvecol {
width: 100%;
float: left;
}
If you have tried multiple solutions (like Ryan Fait's footer or the CSS Sticky Footer (this link is broken, see this instead), which is my favorite) then I would bet that you have a bigger problem than face value. Those two examples have proven the test of time and yet still remain the most commonly used methods for creating a footer which sticks to the bottom of the page. While I'm not bashing your code, I would suggest that maybe you redo the page you're creating from scratch and have the first implementation be the sticky footer. From there you should just be able to copy and paste over your visual styles and if it screws up again then you know your culprit line of code.
EDIT:
I needed to edit your code a bit because the lack of indentation made it difficult to read. Here's the new jsFiddle. What I did change were a few things. Here's the additions to the top of your CSS code:
* {margin:0;padding:0;}
html, body {height: 100%;}
#content-wrap {min-height: 100%;}
Those lines are 100% necessary to make your code work. Not only do you need to do a wildcard (*) reset on all elements, but you also need to tell the document (html) and the body (body) to take up the full height of the screen. I don't remember if it was in your original CSS, but #content-wrap should have a min-height of 100% as well.
After searching through, I realize your footer isn't actually 180px in height, but rather 100px in height. Here's the final jsFiddle. And also, here's the final code to make the footer stick:
#main {overflow:auto;
padding-bottom: 100px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -100px; /* negative value of footer height */
height: 100px;
clear:both;}
You should see now that when you apply this code, the footer sticks to the bottom (and does so without duct tape). Hope this helps!
Majority of the sticky footer codes seem to cause issues with my page. To work around this issue I am using the following code:
HTML
<body>
<div id="page-content">
<header>
<!-- Header Content Goes Here -->
</header>
<!-- Page Content Goes Here -->
<footer>
<!-- Footer Content Goes Here -->
</footer>
</div>
</body>
JS
$(function() {
var height = $(window).height() - ($("header").outerHeight() + $("footer").outerHeight() );
$("#page-content").css("min-height",height+"px");
});
What this does is calculate the height of the page and set a minimum height for the page, thus sticking the footer to the bottom. It works beautifully.
Note: I am using HTML5.
I am making a portfolio website at www.magalidb.0fees.net and I am having some issues with correctly displaying my website in several browsers. The issue is that in some browsers, only the bottom half of the content (which is inside a container) is visible, and the top half is somewhere above reach, at the top of the browser window. To see an example, try opening my website in Firefox, Opera or Internet Explorer.
There are some validation errors, but those are not that urgent. None of those errors is related to the behavior of the website. The site is written in HTML5 by the way, and uses both regular CSS and CSS3.
The issue seems to be with the vertical centering. I center the content of the container both horizontically and vertically.
To center the container horizontically, I used the following CSS:
#container {
min-height: 100%; /* To make sure it reaches the bottom of the browser page */
width: 940px;
margin-left: auto; /* Center horizonticallly */
margin-right: auto; /* Center horizontically */
overflow: hidden;
overflow-y: hidden; /* Vertical scrollbar fix for IE */ }
The vertical centering has the following CSS:
#valigner {
width: 720px;
position: absolute;
top: 50%;
bottom: 50%;
height: 500px;
margin-top: -45%;
margin-bottom: -45%;
margin: -40% 0 0 220px; }
The 220px is only so that the content and header won't stick behind the sidebar.
This is a general layout of the code in the body of my index page:
<body>
<div id="container">
<div id="sidebar" class="left">
<?php include('sidebars/sidebar.php'); ?>
</div>
<div id="valigner">
<div id="sidebar-bottom" class="left"></div>
<div id="head" class="right"><h1>Magali's portfolio</h1></div>
<div id="main" class="right">
<div id="content-textbox">
<div class="intro-left">
Text comes here.
</div>
<div class="intro-right">
<img alt="Me!" class="resizeProfile" src="images/magali.jpg">
</div>
</div> <!-- Closing of div content-textbox -->
</div> <!-- Closing of div main -->
<div id="footer" class="right">
<?php include('language.php'); ?>
</div>
</div> <!-- Closing of div valigner -->
</div> <!-- Closing of div container -->
</body>
Please check out my website (http://www.magalidb.0fees.net). It displays correctly in Chrome and Safari, but incorrectly in Firefox, Opera and Internet Explorer.
I'm very puzzled about this, so any help is very welcome.
!!!EDIT!!!
I found it! It works perfectly now.
I replaced the code from both container and valigner, to the following:
#container {
position: absolute;
top: 50%;
width: 100%;
height: 1px;
overflow: visible;
}
#valigner {
position: absolute;
left: 50%;
width: 940px;
margin-left: -470px;
height: 540px;
top: -270px
}
The code explains itself, it's just so logical. I searched for an alternative method on centering content horizontally and vertically and found this. I feel silly now because I used this method before, yet I neglected it because I thought it was outdated...
Thank you guys for your help anyway! It is greatly appreciated. ;)
PS: I can't answer my own post. I tried, but I get a notification: "Users with less than 10 reputation can't answer their own question for 8 hours after asking. You may self-answer in 5 hours. Until then please use comments, or edit your question instead.".
So I edited my question, like the notification suggested me. I plan on editing the question again after those 5 hours and post an answer the correct way, but until then I can't do better than this. Sorry!
I know you've answered your question, but I'm a bit perplexed about how you've coded your site. There may be a valid reason for it, and if so, a moderator can delete my comment, but I don't think you need all the positioning stuff, especially on both the #container and #valigner elements. In fact, I reckon you could do it using 2 attributes on the #container elements, not using any messy position: absolute; techniques or anything. Here is my suggestion:
#container {
width: 940px; // or whatever you want the width to be. I think this is what you specified originally.
margin: 25px auto; // Centre the design in the middle of the page and put it 25px from the top and bottom of the browser window.
}
I reckon that's it. You could delete #valigner and just use this. If you carry on using position: absolute; everywhere, especially on your top-most containing elements, it will all start to get very messy later on.
<div id="site_wrapper">
<div id="top"><?=$top?></div>
<div id="wrapper">
<div id="login_wrapper">
<?=$content?>
</div>
</div>
<div id="footer"><?=$footer?></div>
</div>
Where
$top should be drawn on the very top of the page.
$content should be centered both vertically and horizontally of the page.
$footer should be drawn on the very bottom of the page.
I do not want either of the divs to follow the view, I found two solutions for the problems one by one, but none to combine them, seeing as they both had the height element in css. So first I guess if it even is possible (which I guess it is) second is then of course, how?
Edit: Pretty much like this side, the top bar should always be on the top, that one is fairly straight forward.
Then the #login_wrapper should always be centered in the site with a fixed height.
Last the footer should always be on the bottom (it should be pushed not stickied), because in this case #login_wrapper wont fill out the site.
The #top and #footer both have fixed heights as well.
Edit2: Fixed some clarifications for the problem.
Found solution from this site [link]http://stackoverflow.com/questions/7909587/horizontal-and-vertical-centering-above-a-sticky-footer-in-css
Thanks anyway!
If i understand your question, try with this css
#site_wrapper
{
position: relative;
}
#top
{
position: relative;
top: 0px;
}
#footer
{
position: relative;
bottom: 0px;
}
#wrapper
{
position:relative;
vertical-align: middle;
height: 100%;
}
#login_wrapper
{
/* add some height */
}