Full screen page with 100% body height - html

Is there any way to make a page with header, sticky footer and the body should always fit 100% of the screen height - header and footer, with only HTML and CSS. See the image for more.
­

You can use an approach which allows you to keep the body at 100% height and have a sticky footer as well using a modern sticky footer approach:
http://mystrd.at/modern-clean-css-sticky-footer/
Steps to achieve this:
1. box-sizing:border-box;
2. html { position: relative; height: 100%;}
3. body{ text-align: center; min-height: 100%; margin: 0; overflow: hidden;}
4. container: absolute positioned with a top of the header height.
5. footer: absolute positioned with left and bottom:0;
Look at this demo:
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
html {
position: relative;
height: 100%;
}
body {
text-align:center;
min-height: 100%;
margin:0;
overflow:hidden;
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 50px; /* Height of Footer */
width: 100%;
}
header {
height: 50px; /* Height of header */
line-height:50px; /* vertical align the title*/
width: 100%;
background-color:lightgreen;
}
.container{
background-color: darkgreen;
height: 100%;
position: absolute;
top: 50px; /* Height of header */
left: 0;
bottom: 0;
width: 100%;
right: 0;
}
footer{
background-color:yellow;
line-height:50px; /* vertical align the title*/
}
<header>HEADER</header>
<div class="container"></div>
<footer>FOOTER</footer>
Inspecting you will see that the body will always be 100% height and the footer will be sticky at the bottom.
Ps. Added box-sizing: border-box just because it's a good practice but it's not necessary for this approach.

If you're using a container in the body after the header then you should set your css like this:
.container {width: 100%; height: 100%; content: "" ;}

Add this to your css
html, body {
height: 100%;
}
And make a div, that has the content you called body, then give it 100% in height.
For an example
<header>..</header>
<section id="content"> <--- HAS 100% IN HEIGHT.
....content
</section>
<footer>..</footer>
Like this:
#content {
width: 960px; <-- definable.
height: 100%;
}

Related

min-height not working on the body

I'm having some issues with min-height: 100%
I want the footer always below my content. Meaning, if the content is longer than the screen height, you don't see the footer, until you've scrolled all the way to the bottom
Also, when the content is shorter than the screen height, the footer needs to be at the bottom of the screen. Well, I thought I solved this just by adding min-height: 100%
<html>
<head>
<style>
html, body, main { min-height: 100% }
</style>
</head>
<body>
<main>
<article> .... </article>
<footer> ... </footer>
</main>
</body>
</htm>
DEMO
Now, for some reason the body tag seems to ignore this setting and its height simply fits the content.
Unfortunately, you can't just set the body to 100% ( DEMO )
Any suggestions how to fix this ?
Sticky footer 'hack' is usually done with the min-height and negative margin-bottom on the footer parent element. All parent elements up until root html, need to have height:100%;
article{
//height: calc(100% - 50px);
min-height: 100%;
background: yellow;
padding-bottom: 50px;
margin-bottom:-50px;
}
JSFIDDLE LONG CONTENT
JSFIDDLE SHORT CONTENT
The fantastic CSS Tricks website has, in their Snippets area a snippet for a Sticky Footer:
http://css-tricks.com/snippets/css/sticky-footer/
Or using jQuery:
http://css-tricks.com/snippets/jquery/jquery-sticky-footer/
latest link with demo
Or you can simply use Modern Clean CSS “Sticky Footer” from James Dean
So just change your HTML and CSS to this:
HTML
<!DOCTYPE html>
<head>
<title></title>
</head>
<body>
<main>
<article> .... </article>
</main>
<footer> ... </footer>
</body>
</html>
CSS
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 100px; /* bottom = footer height */
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
}
Demo here
You can use display:flex for this:
html,
body {
padding: 0;
margin: 0;
height: 100%
}
main {
min-height:100%;
display: flex;
flex-direction: column;
background:blue;
}
article {
flex-grow: 1;
background:green;
}
footer {
background:orange;
}
<main>
<article>... </article>
<footer> ... </footer>
</main>
I modified your css to put the footer and the article in a relative position:
* {
margin: 0;
box-sizing: border-box;
padding: 0;
}
article {
height: calc(100% - 50px);
position: relative;
}
main {
background-color:lightgray;
}
footer {
background-color: green;
height: 50px;
position: relative;
bottom: 0;
width: 100%;
}
the fiddle:
http://jsfiddle.net/np9n4ckb/5/
If you don't want to mess with positioning, you can use vh units.
1vh equals 1% of the viewport's height.
(For reference, this is a good read: https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/)
Fiddle: http://jsfiddle.net/np9n4ckb/6/
CSS
* {
margin: 0;
box-sizing: border-box;
padding: 0;
}
html, body {
min-height: 100vh; /* Minimum height is the full viewport */
}
article {
min-height: calc(100vh - 50px); /* Minimum height is the viewport height minus the footer */
}
main {
background-color:lightgray;
}
footer {
background-color: green;
height: 50px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* browser reset */
html {
height: 100%;
position: relative;
min-height: 100%: padding-bottom: 50px;
/* equal to footer height */
}
body {
height: 100%;
color: #fff;
}
footer {
position: absolute;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 50px;
background: #ccc;
}
header {
background: #333;
}
main {
background: tomato;
}
<html>
<body>
<header>Menu</header>
<main>content of unknown height!!</main>
<footer>footer always stays at bottom</footer>
</body>
</html>
This is just what you need to do.

Bootstrap3 sticky footer overlaps reactive content

I'm using bootstrap in conjunction with Shiny and R. But this doesn't really matter, because Shiny just uses a normal bootstrap installation.
So my footer is coded like this:
/* Sticky Footer */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 40px;
}
.footer {
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 40px;
background-color: #f5f5f5;
}
/* End Sticky Footer
And basically it works nicely. What doesn't work is the resizing I guess after all content is loaded. Since R computes a lot in the background even after the HTML code etc. is loaded, the size of the page usually gets quite bigger after loading. But then my sticky footer overlaps the content and I have been struggling with this now all day and haven't found a solution yet. Any ideas?
<body>
<div id="wrapper">
<div id="main-content">
</div>
<footer>
</footer>
</div>
</body>
CSS:
body,html {
height: 100%;
}
body {
min-height: 100%;
}
#wrapper {
height: 100%;
position: relative;
}
#main-content {
background-color: red;
height: 1000px;
width: 100%;
}
footer {
clear: both;
position: static;
bottom: 0;
height: 40px;
width: 100%;
background-color: blue;
}
Example: https://jsfiddle.net/a5xtu95z/
I don't have much experience with bootstrap but I can't see why this wont work?
Please try this reference link for the Sticky footer layout
http://getbootstrap.com/examples/sticky-footer-navbar/
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}

How to extend div height as tall as the window allows?

I have a common page structure with fixed header and a sticky footer. But I can't get around how to extend the div heights to fill the full window area.
HTML
<header>
header header header
</header>
<div id="page">
<div id="left">side bar side bar</div>
<div id="right">
<p>I want to draw the brown dashed line all the way down to the footer even when the #right content is too little to fill the window.</p>
<p>I know that I have to set height 100% on #right so that it stretches to fill the green box. But, the green box itself does not stretch to the bottom despite height 100% because the yellow box does not have explicit height defined.</p>
<p>What can I do?</p>
</div>
</div>
<footer>
footer footer footer
</footer>
CSS
html, body, foot, header, div { padding: 0; margin: 0; box-sizing: border-box; }
p { margin-top: 0 }
html { height: 100%; min-height: 100%; }
header { position: fixed; background-color: red; height: 50px; width: 100%; }
footer { position: absolute; bottom: 0; width: 100%; background-color: cyan; }
body {
position:relative; /* container for footer */
border: 5px solid yellow;
min-height: 100%; /* not explicitly setting height to allow footer to be pushed downwards */
}
#page {
padding: 60px 0 20px 0;
border: 5px solid green;
height: 100%; /* not working: how to extend page all the way to the bottom, min-height = fill the window? */
}
#page:after { content:""; display: block; clear:both; }
#left { float: left; width: 100px; }
#right {
margin-left: 100px;
padding-left: 10px;
/* objective: to create vertical divider between #right and #left that extends to the footer */
height: 100%;
border-left: 5px dashed brown;
}
OK, the reason why height 100% is not working its because body does not have a height at all, its height depends of the items inside body.
There is a work around for this
Apply the following to your styles.
html, html body {
height: 100%;
}
#page { /* If #page is a lvl 1 child of body, this should work */
height: 100%;
}
Here is the JSFiddle
http://jsfiddle.net/wetjyLy3/1/
You can use absolute positioning to make the divs always 0px away from the top and bottom of the window. You may need to play around with the values, but something like this should work:
#left { position: absolute; top: 0; bottom: 0; left: 0; width: 20%; }
#right { position: absolute; top: 0; bottom: 0; right: 0; width: 80%; }
Edit: Here's a fiddle that shows how this could work.

How to make a footer stick to the bottom of the page

I have read all the tutorials on how to make the footer at the bottom of the webpage but still i'm unable to do it for my site.
The links i have referred are
How do you get the footer to stay at the bottom of a Web page?
Making my footer stick to bottom of the page
Ways to stick footer to the bottom a page
making the footer stick the bottom
None of it worked..!
CSS
#footer1 {
clear: both;
background-color: #333;
width: 1200px;
min-width: 100%;
width: 100%;
bottom: 0;
position: relative;
height: 50px;
border-top:5px solid #1b9bff;
}
Here is the dummy fiddle of my site
Fiddle
This is the fiddle i have tried but there is a bug in it too
http://jsfiddle.net/andresilich/fVpp2/1/
Try this:
<div id="container">
<div id="content"></div>
</div>
<div id="footer">My Sticky Footer</div>
CSS:
html, body, #container { height: 100%; }
body > #container { height: auto; min-height: 100%; }
#footer {
clear: both;
position: relative;
z-index: 10;
height: 3em;
margin-top: -3em;
}
#content { padding-bottom: 3em; }
Add/Edit as following
#body {
margin-bottom: 85px;
position: relative;
}
#footer1 {
position: fixed;
}
I guess this is what you want
* html #form1 {
height:100%;
}
#form1 {
min-height: 100%;
position: relative;
}
#body {
padding-bottom: 50px; /* padding-bottom should be equal to the footer height (this keeps the footer from overlapping the content) */
}
#footer1 {
position: absolute;
width: 100%;
clear: both;
bottom: 0;
padding: 0;
margin: 0;
}
Following the code of this method - you need to to:
1) Place your footer outside the form
2) Add height: 100% on form
3) Set negative bottom margin to form according to the height of the footer.
form {
min-height: 100%;
height: 100%;
margin: 0 auto -150px; /*footer 150px high */
}
Modified Fiddle

scrollbar not working properly in div with fixed header and footer

I am building a website and I am facing some problems with the scrollbar for divs. I have a fixed header and footer and the divs in between must stay between the header and footer. In case of overflow a scroll will appear.
What I am Trying is similar to How to get a scrollbar in a div with fixed header and footer?
But I cant make it work correctly.
JS Fiddle of What I Am Trying
Fiddle
I could make it work by giving body{height: 84%;} but it will different in different browsers.
EDIT:
Now that jsfiddle is back...
Here is an updated fiddle for what you wanted
the following is the main change that was necessary:
div[role="main"]
{
height: 100%;
background: pink;
margin: -70px 0 -30px;
padding: 70px 0 30px;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #4CD3BF;
}
Do something like this:
Not much content: CODEPEN1
Lots of content: CODEPEN2
Markup
<div class="container">
<header></header>
<div class="content"></div>
<footer></footer>
</div>
CSS
/* Assuming header and footer height of 64px */
.container
{
height: 100%;
background: pink;
margin: -64px 0;
padding: 64px 0;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.content {
overflow:auto;
height:100%;
}
header
{
height: 64px;
background: purple;
position: relative;
z-index:1;
}
footer
{
height: 64px;
background: gray;
position: relative;
z-index:1;
}
there are more than 1 answers to this problem. the easiest way to do this is to wrap the main content (so no header and footer) in a absolute positioned div. set the divs to to the bottom of the header and the bottom to the top of the footer eg
fiddle: http://jsbin.com/onipiq/2/edit
css :
body{
margin: 0;
padding: 0;
}
header{
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100px;
background: #eee;
}
footer{
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 100px;
background: #eee;
}
.contentContainer{
position: absolute;
width: 100%;
top: 100px;
bottom: 100px;
overflow-y: scroll;
}
.content{
position: relative;
width: 960px;
margin: 0 auto;
}
Note that this example will not scroll on most touch devices but will work fine on desktop.