I have two footers at the bottom of my page. I want one of them to always be fixed, then when i scroll to the bottom I want the other to pop-up under it so basically when I reach the bottom of the page, the "normal" footer should be under the fixed footer. Here is what I have so far I'm using the navbar bootstrap class to fix it to the bottom. So what this code does now is when i reach the bottom, the fixed footer is the bottom footer, I want it the other way around.
<footer class="footer" role="footerinfo">
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<div class="col-sm-12">
//When I reach the bottom this shoud be top footer
</div>
</div>
</div>
<div class="wrapper">
<div class="container">
<div class="row">
<div class="col-sm-12">
//Should not be fixed, be below fixed
</div>
</div>
</div>
</div>
</footer>
Anyone know what kind of css styling i need to fix this
I put together a solution that doesn't use any javascript. Is this what you were looking for?
https://jsfiddle.net/j611yLem/3/
Here is the CSS I used:
body {
padding: 0;
margin: 0;
}
.container {
position: relative;
padding-bottom: 40px;
}
.first-footer {
position: fixed;
bottom: 0;
background: red;
left: 0;
right: 0;
padding: 10px;
color: #FFF;
}
.second-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
width: 100%;
background: blue;
padding: 10px;
color: #FFF;
}
Essentially, you have the first footer be fixed in position, and the second footer absolutely positioned to the bottom of the container.
I wasn't sure if you meant positioned on top of the footer (hiding it) or slightly above. If you want the second footer to cover the first, change the bottom padding of the container to 0px.
I think this person's question could help you do exactly that: Stop fixed position at footer
Basically the footer stays fixed until it's within a certain range then the css style changes to absolute. Take a look at the live demo from the top rated answer.
Check the offset when you scroll:
$(document).scroll(function() {
checkOffset();
});
Make the position absolute within a certain range, you'll need to tweak this yourself.
function checkOffset() {
if($('#social-float').offset().top + $('#social-float').height()
>= $('#footer').offset().top - 10)
$('#social-float').css('position', 'absolute');
if($(document).scrollTop() + window.innerHeight < $('#footer').offset().top)
$('#social-float').css('position', 'fixed'); // restore when you scroll up
}
And whatever you use instead of #social-float will need to be a sibling of the footer:
<div class="social-float-parent">
<div id="social-float">
something...
</div>
</div>
<div id="footer">
</div>
I hope this helps. Their question is extremely similar to yours so I didn't want to re-invent the solution.
Related
Say I have three divs like following:
<div class="wrapper">
<div class="container">
container1
<div class="element">
fixed
</div>
</div>
<div class="container2">
container2
</div>
</div>
I want div: element to be fixed when it is inside div: container, but its position should become absolute when div: container2 becomes visible, it should not overlap with div - container2, but scroll away at that time with div: container.
A pure CSS solution is preferable, but if not possible I may go for a JS or jquery solution. I have created a fiddle for this, and tried some solution suggested here, which are not working.
What I would suggest is to use javascript to recognize when the scrolling is at a certain point with window.pageYOffset
When it reaches your desired window Y Offset you can start an event that modifies the css value of the positioning from fixed to absolute (by setting the parent container to relative) and bottom at 0.
Check out this jsfiddle https://jsfiddle.net/zq0kkkcx/2/
Also, this is the code that I'm talking about:
document.addEventListener("scroll", function(event) {
if(window.pageYOffset >= 1200){
console.log("1200");
// this is where you want your element to become absolute
// positioned to his parent container
// write your css changes here and apply them to elements
// add relative to container and absolute with bottom 0 to element
} if (window.pageYOffset <= 1200){
console.log("<1200");
}
});
If you want a CSS solution, here is a trick that you can do using z-index. Other than this there is a JS solution.
.wrapper {
width:100%
}
.container {
width:300px;
margin:0 auto;
height:1200px;
background:#ccc;
position: relative;
z-index: -1;
}
.container2{
width:300px;
margin:0 auto;
height:1200px;
background:#fcf;
z-index: 1;
}
.element {
background:#f2f2f2;
position:fixed;
width:50px;
height:70px;
margin-left:250px;
border:0px solid #d6d6d6;
}
<div class="wrapper">
<div class="container">
container1
<div class="element">
fixed
</div>
</div>
<div class="container2">
container2
</div>
</div>
You're looking for a sticky header. There is currently no way to make a header sticky at an arbitrary scroll position using pure CSS - you'll have to look into a JavaScript solution to accomplish that.
Yes, it is 100% possible to do this without any JavaScript
I updated your fiddle
Markup should be like this
<div class="wrapper">
<div class="outer-scroller">
<div class="scroll-container">
container1
<div class="fixed-header">
fixed
</div>
</div>
</div>
<div class="last-container">
container2
</div>
</div>
and css
.wrapper {
width: 100%;
height: 300px;
}
.outer-scroller {
height: 140px;
overflow-y: scroll;
}
.scroll-container {
padding-top: 70px;
width: 300px;
height: 1200px;
background: #CCC;
}
.last-container {
width: 300px;
height: 600px;
background: #FCF;
}
.fixed-header {
background: #F2F2F2;
position: absolute;
width: 300px;
height: 70px;
top: 0;
pointer-events: none;
}
You'll see I've added an outer-scroller div.
The next bit is changing your CSS slightly
The new outer-scroller div is double the height of your fixed-header (for the purposes of this example) and it has an overflow-y: scroll on it.
The container inside there is still the same.
The next change is turning your position: fixed into a position: absolute and then adding padding to the top part of the div you want to scroll in order to push its content "below" the new "fixed" header.
Scrolling over the outer-scroller div then makes its content scroll, and because its height is set with an absolute element on top it then scrolls "under" the fixed header.
Once the bottom of its child content scroll-container is reached, the whole page then continues scrolling, and you get the illusion of the header disappearing.
The last bit is pointer-events: none on the header so that it doesn't scroll away when the cursor is over it (but the div below does)
To start off I'm relatively new to CSS, Bootstrap and HTML. I want to position a responsive element at the bottom of the screen.
So I have this code which makes it behave responsively:
<div class="col-sm-12">
test
</div>
But how do I get it to stick to the bottom of the page? I already tried ID/ Class selectors with an absolute position. It moved the element to the bottom, but it wasn't responsive anymore.
One solution might be to wrap the desired element in another div, then target the wrapper element to fix it to the bottom of your screen. Your markup could look like:
<div class="fixed-container">
<div class="col-sm-12"><!--your content here--></div>
</div><!--end .fixed-container-->
And you styles could look like:
.fixed-container {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
}
This would affix the .fixed-container element to the bottom left of the viewport, and would set the width to 100% of the viewport. The layout-specific rules applied to .col-sm-12 would remain intact.
<div id="my-element" class="col-sm-12">
test
</div>
#my-element {
position: fixed;
bottom: 0;
}
Here is a simple solution to your problem.
Make sure your elements are in a wrapping div. Since you are using Bootstrap, use:
<div class="container-fluid">
Inside this container place your elements/sections including your footer:
<footer class="col-md-12">
Your footer should have the following CSS.
footer {
position: absolute;
bottom: 0;
height: 100px /* Height of your footer */
width: 100%;
}
Here is a fiddle. You can see the footer is at the bottom of the container which has a black border.
http://jsfiddle.net/gward90/ehf2wm83/
I am having some issue trying to implement sticky footer, that is to make the footer stay at the most bottom of the page, I think this problem is due to the fact that I use 2 divs to render rounded corners for my page, I have searched for all possible solution and tried them, nothing works.
So basically, this is my design:
<div class="global">
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div></div>
</div>
</div>
This is my CSS:
body {
font-family: Verdana, Geneva, sans-serif;
}
#global {
margin: 0 auto;
width: 85%;
min-width: 1020px;
}
.wrapper {
background: #FFFFFF;
}
.footer {
background: url('../Images/roundedcornerRIGHT.gif') no-repeat bottom right;
}
.footer div {
height: 40px;
background: url('../Images/roundedcornerLEFT.gif') no-repeat bottom left;
}
.footercontent {
text-align: center;
font-size: small;
}
No matter what solution I try posted by other people on Stackoverflow, nothing works, it will either not move the footer down to the bottom of the page, or it just messes up with the footer's layout of the rounded corners.
Try this:
.footer {
background: url('../Images/roundedcornerRIGHT.gif') no-repeat bottom right;
position: absolute;
bottom: 0;
}
If you want footer at the bottom give a minimum height to your content.
min-height: 800px;
Change your markup to this:
<body>
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
</div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div></div>
</div>
</body>
And then add these styles:
.footer {
position:fixed;
left:0px;
bottom:0px;
width:100%;
}
Okay, so assuming you want to keep everything you are currently doing.. I have a quick fix for you. Now, a few things to note.. I did add in a height variable to your 'wrapper' class because I needed to gauge it as if there were space inside of the wrapper itself. I also went ahead and put in a few colors to let me know exactly where I am. Either way, the simplest fix is to take your footer div and put it outside of the wrapper. The way this all works is, the footer is showing up inside of the wrapper class, the only problem is that nothing else is showing up in that class, which causes the footer to be the only thing.. creating the problem of having this footer at the top. However, if you would like to stay current with every page, moving the footer down to the bottom of the global div should be your fix, the code below:
<div class="global">
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
</div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div>
</div>
</div>
So the problem really was in the HTML, not the CSS. You can keep your CSS or play with it as you please but to better describe what I am saying, I have been fiddling (haha) with a JsFiddle for you :) Comment below if I need to make more sense of what I am saying!
I've been tasked with changing a website around a bit, and right now, the website has a responsive layout that is 95% of the viewports width, body-wise, so it will adjust if resized.
This is great, I want it to keep doing that, but I want the footer to have a side-to-side calm blue background, and I'm not able to come up with a way to do that for some reason.
Can anyone help?
Try this - DEMO
HTML
<div id="container">
<h1>TITLE</h1>
<section>MAIN CONTENT</section>
<footer> FOOTER </footer>
</div>
CSS
#container {
width: 95%;
margin: auto;
background: honeydew;
}
footer {
position: absolute;
width: 100%;
background: beige;
margin-left: -2.5%;
}
body contains all the other elements. You thus aren't supposed to have one larger than body inside of it.
Although you could position it absolutely to the bottom-left corner (position: absolute; bottom: 0px; left: 0px;) with a width of 100% and possibly make it work, I'd suggest you instead make a container element, perhaps a div, inside of the body element that contains your 95%-width elements and place the footer outside of that container.
I am not sure of which method is more reliable, however.
Have You tried to wrap existing 'header'component by other 'wrapper' component (div, span, etc.)? Example:
<div id="wrapper" width="100%"
<div id="header" width="95%">
some header stuff here
</div>
<!-- foo bar -->
<div id="footer" width="100%">
my footer
</div>
</div>
The web page layout of my website look something as follows:
The web page layout of my website look something as follows:
<body>
<div class="container">
<div class="sidebar">
</div>
<div class="content">
</div>
</div>
<div class="pre-footer">
</div>
<div class="footer">
</div>
</body>
Css:
body {background:#eaeaea url('../images/bg/sfere.jpg') no-repeat top center fixed;}
.footer {float:left;width:100%;height:67px;background:url('../images/bottom.png') bottom center;bottom:0px;left:0px;}
.container{padding-top:5px;margin-left:100px;margin-right:auto;}
.sidebar {float:left;width:220px;min-height:610px;text-align:center;}
.home {margin:178px 0 0 100px;padding:0 10px 0px 10px;width:800px;float:left;}
.pre-footer {float:left;width:98%;height:100px;position:relative;background:url('../images/pre-footer.png') bottom center;left:15px;bottom:-32px;}
All the elements are appearing fine in layout. However, the problem is when the height of the container is less, the footer elements stick below the container and don't stay in the footer position. Similarly, if I manually fix the height as 600px to make it look like a footer, on browser resize, the footer still stick below the container and doesn't look like a footer.
How do I rectify this problem?
Use fixed position for your footer.
div.footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
max-height: 50px; /* change this as needed */
}
and specify a bottom padding to your body to ensure all content is visible when scrolled.
body {
padding-bottom: 50px; /* change this to the max-height given for your footer */
}