Forcing div/image to bottom of screen regardless of the screen size - sticky-footer

EDIT 10.12am 17th April.`Your jsfiddle and on the emulator works perfectly and as I would expect however I am having no luck. My html is
<img src="/images/mobile/m_tech_fuss.png" alt="Payco Tech logo" width="100%">
<div id="wrap">
<div id="main">
<div><img src="images/mobile/m_tech_welcome.png" width="100%" />
</div>
<div><img src="images/mobile/m_tech_self_e-contracts.png" width="100%" />
</div>
<div><img src="images/mobile/m_tech_optout.png" width="100%" />
</div>
</div>
</div>
<div id="footer"><img src="images/mobile/m_tech_soundsgood.png" width="100%" />
</div>
and css is exactly as you stated however not only does this not move the orange footer image at all but it also messes with my homepage layout :(
EDIT: 5.10pm 6th April
I found a guide which appears to work ok http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
The orange footer stays at the bottom on any mobile screen however there is still some a gap between the last bit of content and the footer which forces me to scroll down whereas on a page where there is little content, the footer should just be sitting there already. Also this guide has messed up with my green strip images which are now no longer 100% in width :(
Here is my code:
<div id="container">
<div id="header"></div>
<div id="body">
<div><img src="images/mobile/m_tech_welcome.png" width="100%"></div>
<div><img src="images/mobile/m_tech_self_e-contracts.png" width="100%"></div>
<div><img src="images/mobile/m_tech_optout.png" width="100%"></div>
</div>
<div id="footer"><img src="images/mobile/m_tech_soundsgood.png" width="100%"></div>
</div>
and my css
`}
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#fff;
padding:10px;
}
#body {
padding:10px;
padding-bottom:70px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:70px; /* Height of the footer */
content:url("../images/mobile/m_tech_soundsgood.png");
}
#container {
height:100%;
}`

If all you want is for that image to always sit at the bottom of the screen, it looks like you are making it a bit too complicated. Try:
div#content
{
position: fixed;
bottom: 0px;
}
To get CSS sticky footer to work you can't have any content outside of the #wrap or the #footer divs or it will mess up the height calculations. It will push the #wrap div, which has a min-height of 100%, down the page. This means that the bottom of the #wrap div is lower than the bottom of the screen. Resulting in unreliable behavior. Especially if the height of the content outside the #wrap or the #footer divs is of variable height, which is what was happening in this particular case.
You can either place a header inside the #wrap div in a config much like this:
<div id="wrap">
<div id="header">
<!-- Header content -->
</div>
<div id="main">
<!-- Main content -->
</div>
</div>
<div id="footer">
<!-- Footer content -->
</div>
Or you can leave it outside of the #wrap and #footer div and compensate by adding a padding-top value equal to the height of the header on the #main div. This is to stop the content inside the #main div from rendering over the top of the header outside of the #wrap and #footer divs.

Related

Sticky footer behind main content, visible on scroll

I would like to re-create this revealing sticky-footer effect found at http://www.akc.org/dog-breeds/
I know the footer has to be fixed.
I know the content needs to have a higher z-index
I'm guessing (sort of) that the body needs to have a margin-bottom which is equal to the height of the footer???
Please would someone help me out.
I'm using Twitter Bootstrap 4. The general markup looks like this:
<body>
<div class="container"> <!-- This part should scroll up to reveal the footer below -->
<!-- Content goes in here -->
</div>
<footer class="footer"> <!-- This should be hidden initially -->
<div class="container">
<div class="row">
<!-- Footer stuff goes in here -->
</div>
</div>
</footer>
</body>
You will want to add a main content div and then give this div a background color of whatever you want your page to be otherwise you will just end up having text overlapping but yes you are right you will want to give your main content div a z-index of 1 or something and then fix your footer behind that and give it a z-index smaller than that in my example I gave it a z-index of -1. Then your main content div will scroll over the top of your footer. You will probably want to give your footer a height and your body a padding-bottom of the same height.
Here is an example of how I did it Fiddle Demo:
Html:
<div class="main-content">
<div class="container">
<div class="row">
Your main Content Scroll down
</div>
</div>
</div>
<footer>
<div Class="container">
<div CLass="row">
Footer Content
</div>
</div>
</footer>
Css:
body{
padding-bottom:200px;
}
.main-content{
min-height:200vh;
background:#fff;
z-index:1;
}
footer{
position:fixed;
bottom:0;
left:0;
width:100%;
height:200px;
background:#000;
color:#fff;
z-index:-1;
}

Fixed Parts of page: Header, Content and Footer

I need 3 parts: Header, Content and footer for my page in fixed position.
<body>
<div id="header">
<div id="info">
<span id="fa">test</span>
<br>
<span id="en">Honey Koohpayeh Official Website</span>
</div>
</div>
<div id="section">
<div class="img-holder">
<img class="img" src="img/img1.jpg" />
</div>
</div>
<div id="footer">
Copyright © W3Schools.com
</div>
</body>
CSS:
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#section {
padding:10px;
text-align: center;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
And I'm using java script having two pictures which pic one loads at first then a loading.gif shows and then the second pic shows up.
The problem is when i show the loading, and then show the second pic, the content get empty for a sec and my footer reaches to the header. I need the three parts fixed position and nothing can changes their height. And i wanna use % like header and footer get 20% and the content gets the rest.
One option is to set a fixed height and width while the image loads and remove it when the image is received.

Can't set height 100% on floated element

I've managed to position two divs next to each other by using the following code however my left div won't allow a height:100% and seems to be defaulting to auto, how can I set the height to 100% with my current setup?
css:
.left_div
{
width:30%;
height:100%;
padding:10px;
text-align:center;
float:left;
overflow:hidden;
}
.right_div
{
word-wrap:break-word;
float:left;
width:65%;
margin-left:15px;
overflow:hidden;
}
html:
<div class='panel-body thread-body'>
<div class='panel panel-default original-post-panel'>
<!-- dynamically generated content -->
<div class='panel-body'>
<div class='left_div'>
<!-- dynamically generated content -->
</div>
<div class='right_div'>
<!-- dynamically generated content -->
</div>
<div style="clear:both">
 
</div>
</div>
</div>
Height of the floating divs doesn't goes up to the parents.
Thus, the height of the parent div will be 0.
Thus, the height of your left div will be also 0 if its height is set to 100%.
Thus, the content of your left div will overflow, and it will be visible only because of this overflow.
The simplest solution for your problem would be if you would put an empty div with clear: both after all of them:
<div class="left_div">...</div>
<div class="right_div">...</div>
<div style="clear: both"> </div>
Effectively, it will be a similar effect as if you would start an empty "new-line" (despite there is no textual line rendering here).

Why is only the top half of my website responsive?

Why is it that the top half of my website (header-wrapper and menu-wrapper) is responsive, but the bottom (featured-wrapper and footer) isn't?
Recently, I've noticed that this responsive website behaves strangely when the screen is smaller than about 1000px. The header and navigation menu shrink to fit the screen size, but the content wrapper, called #featured-wrapper, and footer don't. The content is cut off, and where they cut off they are replaced with a dark charcoal colored bar that is the same as the footer color. When the website is viewed in a larger browser it centers perfectly.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="header-wrapper">
<div id="header" class="container">
<h1></h1>
<br>
<h2></h2>
</div>
</div>
<div id="menu-wrapper">
<div id="menu">
<ul>
<li>
<!-- content -->
</li>
</ul>
</div>
</div>
<div id="wrapper">
<div id="featured-wrapper">
<div class="extra2 container">
<div class="ebox1">
</div>
<div class="title">
<!-- content -->
</div>
</div>
</div>
</div>
<footer>
<div id="copyright" class="container">
<p></p>
</div>
</footer>
</body>
</html>
CSS for #featured-wrapper is:
#featured-wrapper
{
overflow: hidden;
padding: 10em 0em;
background: #FFF;
text-align: center;
}
Your css specifies
.container {
width: 1200px;
...
}
which is used in both the footer and the main content. One possible fix to this is to change it to
.container {
max-width: 1200px;
...
}
so that it will stretch to the width of its parent but will never go larger than 1200px wide.
This occurs because of this css:
overflow: hidden;
This prevents the #featured-wrapper element to show the slide bars:
CSS overflow Property
The overflow property specifies what happens if content overflows an element's box.
hidden The overflow is clipped, and the rest of the content will be invisible

setting a footer to the contents or pages end

I'm looking for a possibility to set the footer to the end of my page or the end of my content if the content is greater than one page.
I do not want to have a fixed footer where the content is scrollable.
I do not know whether it is possible.
So, this is my code.
The div with class="div1" contains the content.
The content contains the content as well as the footer.
<div class="div1">
<div class="content">
<div class="myContent"></div>
<div class="myContent"></div>
<div class="myContent"></div>
<div class="footer"></div>
</div>
</div>
The footer has a height of 50px.
My problem is following:
If I have a screen height with height:500px and the content is only 150px high, the footer is set after the last div-element with class="myContent".
It should be set to the end of the page like the effect I receive with
bottom:0;position:fixed
But if the content is 600px high the footer should be set right after the last div with class="myContent". No styles would be needed here.
Have you got an idea how to solve it?
do you mean Make the Footer Stick to the Bottom of a Page ?
or this one
the css
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {overflow:auto;
padding-bottom: 150px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;}
and the html
<div id="wrap">
<div id="main">
</div>
</div>
<div id="footer">
</div>
I think this may help you get rid off this problem:
.footer {position:absolute;left:0;right:0;bottom:0;background:green;height:50px}
This may solve the objective:
<div style="position:absolute">
<div style="position:absolute">
<div id="top" style="height:50px;width:100%;position:fixed;left:0;top:0;background:red"> content 1 </div>
<div id="middle" style="background:green;position:fixed;top:50px; left:0;bottom:50px;right:0">content 2 </div>
<div id="middle" style="background:blue;position:fixed;top:100px; left:0;bottom:50px;right:0">content 3 </div>
<div id="bottom" style="height:50px;width:100%;position:fixed;left:0;bottom:0;background:orange">Footer</div>
</div>
</div>