I am wondering how I can get the footer to stay at the bottom when there is not enough content.
If I use this for the cssposition:absolute;
bottom:0;
The problem is if there is more than enough content the footer floats and overlays the content.
http://niceguy.co/
Thanks.
http://www.cssstickyfooter.com/ should be what you're looking for.
You need to define position: fixed; bottom: 0; width: 100%;
Your structure needs to look something like this:
<body>
<section id="wrap><!-- This has header, etc --></section>
<footer></footer>
</body>
then CSS (where 50px is the height of your footer, just replace that):
html, body { height: 100%; }
#wrap {
min-height: 100%;
padding-bottom: 50px;
}
footer {
height: 50px;
margin-top: -50px;
}
Related
I know this is a duplicate question, I've read through many questions on this particular question like this one.
But I can't for the life of me get mine to work. I've tried many combinations of height and min-height for my html and body, using both % and vh. I tried setting the margin to 0 as well but that doesn't help. I tried this on both Chrome and Firefox, neither browser works. There were some answers that suggested using position: absolute but that messes up the styling for all the content I have.
Some combos I tried:
html, body{
height: 100%;
min-height: 100%;
}
html{
height: 100%;
}
body {
min-height: 100%;
}
html{
height: 100%;
margin: 0;
}
body {
margin: 0;
min-height: 100%;
}
My HTML layout:
<html>
<head>
... stuff
</head>
<body class=".container">
... stuff
</body>
</html>
You can use a fixed position for the bottom, but that can leave you with display problems as content gets covered.
I recommend using something like
body {
height: calc(100vh - 100px);
}
if you want to leave 100 px for your header and footer
What you're looking for is position: fixed, which tells the element to be fixed to that location, regardless of the other content. Couple this with bottom: 0, to state that the element should be fixed to the bottom of the page:
body {
margin: 0;
}
div {
padding: 5px;
}
.container {
background: #DDD;
height: 50px;
}
.footer {
position: fixed;
bottom: 0px;
height: 20px;
width: 100%;
background: #DDD;
}
<body>
<div class="container">Text</div>
<div class="footer">Copyright</div>
</body>
Hope this helps! :)
Solution :You can use the html 5 elements like
Header,
Article,
Section,
Footer
And set there height and width according to your requirements...
you can use this code to create a fixed footer at the bottom of your page
.yourfooterclass {
position:fixed;
left:0px;
bottom:0px;
height:30px;
width:100%;
background:#999;
}
basically what this is doing is positioning the footer at the very bottom of the page, so it doesnt matter how much content you have on the page it will always be at the bottomn
Since I couldn't change anything on the height-property of the body, I found this solution at https://www.freecodecamp.org/news/how-to-keep-your-footer-where-it-belongs-59c6aa05c59c/1, also pure CSS:
The html structure:
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<div id="page-container">
<div id="content-wrap">
<!-- all other page content -->
</div>
<footer id="footer"></footer>
</div>
</body>
</html>
And the CSS accordingly:
#page-container {
position: relative;
min-height: 100vh;
}
#content-wrap {
padding-bottom: 2.5rem; /* Footer height */
}
#footer {
position: absolute;
bottom: 0;
width: 100%;
height: 2.5rem; /* Footer height */
}
I have four DIVs :
The first div has a fixed height and located on top (header).
The second div also has a fixed height and located below the first div.
The fourth div has a fixed height located on bottom.
The third div will have a variable height: it will expand to make the total of four divs are full to vertical space in browser IF the content is less than that. But it will follow the content's height if the content's height is larger than that. So at all times, I want the first div (the header) to stick at the top of the page, and the fourth div (the footer) to stick at the bottom of the page. I have no way to know how tall the content will be.
header
header
header
header
the CSS file:
#container { width:800px; height:*; }
#header { height:200px; }
#menu { height:50px; }
#content { height:*; }
#footer { height:150px; }
can I actually do this? how is the correct css way to do this? I get the feeling this should be not too hard, but I can't find relatable answers anywhere. Thank you.
What you could do is something like this:
#content { height: 100vh; /*100% of viewport height*/
margin-top: 250px;
margin-bottom: 150px; }
This way it will always be 100% of the screen height in total.
Well that turned out looking cool, JSBin
HTML
<div class="header">Header !</div>
<div class="menu">Menu !</div>
<div class="content">Content !</div>
<div class="footer">Footer !</div>
CSS
body { margin: 0; }
.header { width: 100%; height: 200px; position: fixed; top: 0; }
.menu { width: 100%; height: 50px; position: fixed; top: 200px; }
.footer { width: 100%; height: 150px; position: fixed; bottom: 0; }
.content { width: 100%; position: fixed; top: 250px; bottom: 150px;
overflow: auto; }
I am trying to create a page which will be have header and footer div with unknown height (or min-height) and middle content with scroll if the content increases and all these three should fit in screen only.
I tried below and works if the height of header and footer is fixed and if only middle content increases then i get scroll for content div perfectly. How do to handle unknown height part for header and footer to make it fit? I gave min-height but doesn't work.
#Pageheader {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 100px;
background-color: Blue;
}
#Pagefooter {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100px;
background-color:red;
}
#Pagecontent {
position: fixed;
top: 100px;
bottom: 100px;
left: 0;
right: 0;
background-color: #EEEEEE;
overflow: auto;
}
and Html side
<body>
<form id="form1" runat="server">
<div id="Pageheader">
</div>
<div id="Pagecontent">
</div>
<div id="Pagefooter">
</div>
</form>
The ol' school dirty way is to use Jquery. Detect height of header/footer, place and resize the content div according to window height and the previous heights.
A sophisticated solution is to use Flexbox. Using the align-content: stretch you can create the layout you want. You can check it here.
I got stuck trying the same thing last week. I ended up doing it with css tables (compatible with all browsers including IE8). Here's the CSS for it:
/* Layout-1 | Header Footer */
html {
min-height: 100%;
}
html, body {
height: 100%;
width: 100%;
}
body {
display: table;
}
header, footer {
display: table-row;
padding: 30px;
}
div#container {
display: table-row;
height: 100%;
}
If you wanted a fixed header and footer and for the scrolling to only effect the body section in between, the markup and css would be totally different, and utilize position: absolute;
Let me know if this works for you : )
I have what is a fairly common page layout where the content div is centralised on the page using margin:auto 0. The width of the div itself varies depending on available page width.
I want another div featuring a logo to 'stick' to the outside left hand side of this div (ie no gap or overlap between the two) at a fixed height. What CSS should I use for this?
something like
html:
<html>
<div id='content'>
<div id='stickything'>a</div>
</div>
</html>
css:
html {
width: 100%;
}
#content {
position: relative;
width: 100px;
height: 600px;
margin: auto;
background-color: green;
}
#stickything {
position: fixed;
width: 25px;
height: 30px;
top: 0px;
margin-left: -25px;
background-color: red;
}
http://jsfiddle.net/Kkcnn/
Use position:absolute. It must help:
.container-div{
position: relative
}
.outer-div{
position:absolute;
top: 0 (your choice)
left: -/outer div's width/
}
I am trying to make a sticky footer, and my page's html structure is like this: (vastly simplified)
<head>...</head>
<body>
<div class="centerPane">
<div class="userCenter">..</div>
<div class="bottom>...</div>
</div>
</body>
css:
head
{
height: 100%;
}
body
{
min-height: 100%;
height: 100%;
}
.userCenter
{
position:relative;
height: 100%;
}
.bottom
{
position: absolute;
bottom: 20px;
height: 30px;
}
For some reason, this is pushing the bottom OFF BEYOND the bottom of the page regardless of the browser window size on firefox 10.0.1.
Here is a demo: 173.228.119.111:3000/users/sign_in
not quite sure what the problem is, but I would take a look at this http://www.cssstickyfooter.com/using-sticky-footer-code.html you seem to be missing some css...
You could try setting the margin on the footer to a negative value i.e.:
margin: -4em;