3

Is there a way for the footer to be positioned at the bottom no matter how much content is on the page and the content does not overlap with the footer?

Thank You for all your help

3
  • 2
    Yes, this is possible. However, what have you tried so far, and what issues are you facing?
    – Someone
    Commented Apr 12, 2016 at 16:30
  • Yes, there definitely is.
    – Shomz
    Commented Apr 12, 2016 at 16:30
  • Use google with words "html footer bottom" Commented Apr 12, 2016 at 16:35

2 Answers 2

0

Flexbox might be a solution which is pretty flexible. The footer will always be at the bottom of the page unless there is too much content, then it will just be at the end of the page (thus no "overlapping").

document.getElementById("expand").addEventListener("click", function() { document.getElementById("long").style.display = "block"; });
* {
  box-sizing: border-box;
}
#container {
  display: flex;
  flex-direction: column;
  align-content: stretch;
  height: 100vh;
}
header, footer {
  flex-basis: auto;
  flex-grow: 0;
  padding: 20px;
  background: #ccc;
}
div#content {
  flex-grow: 1;
  padding: 20px;
}
div#long {
  display: none;
}
<div id="container">
  <header>This is the header with auto-height.</header>
  <div id="content">Short Content. <span id="expand"><strong><u>Click here more content!</u></strong></span>
  <div id="long"><img src="http://placehold.it/350x1000"></div></div>
  <footer>This is the footer, and always at the bottom of the window unless there's too much content.</footer>
</div>

0

A better idea can be utilizing a css framework like twitter-bootstrap. but if you want to achieve that with css only, something like this in your css file will give you what you need:

footer {
    width: 100%;
    bottom: 0;
    position: fixed;     
}

In order to make sure, any content and footer will not overlap you can either set a padding-bottom in your body:

body {
    padding-bottom: 60px;
}

or have a content div which you set its 'margin-bottom':

.content {
    margin-bottom: 60px;
}

jsfiddle

7
  • 1
    That only gets them half way. They need to also make sure, as they say, that the footer doesn't overlap any content. You'll likely need to set a height on the footer, and a corresponding padding on the body - alternatively, some JS might be in order.
    – Someone
    Commented Apr 12, 2016 at 16:45
  • @AliSeyedi Why did you use in the footer position:fixed, wouldn't it be better to use position:absolute? Commented Apr 12, 2016 at 17:20
  • @RobertoFlores Because a fixed positioned element will stay where it is when the page is scrolled. And absolute positioned elements will be relative to the first positioned parent. I thought fixed is more appropriate for you as you required it "to be positioned at the bottom no matter how much content is on the page".
    – Ali Seyedi
    Commented Apr 12, 2016 at 17:27
  • @AliSeyedi I see. But the issue is the page can change meaning there will be time that content can be one line and I was wondering if the footer can remain in the bottom. Commented Apr 12, 2016 at 17:37
  • @RobertoFlores with fixed positioning, the footer should remain in the bottom.
    – Ali Seyedi
    Commented Apr 12, 2016 at 17:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.