Chrome causing footer to not remain fixed at the bottom

I've been experimenting with flexbox in order to keep my footer at the bottom of the page, but only when the content is shorter than the viewport. The goal is for the footer to stay below the content if the content is taller, requiring users to scroll to see it.

Interestingly, this setup functions correctly in Firefox and Edge, but not in Chrome or IE.

In Chrome, you'll notice that reducing the viewport size results in the footer becoming "stuck" to the bottom of the screen. Upon scrolling, the footer remains fixed in place and moves up the page.

The culprit seems to be the contentContainer:

#contentContainer {
  display: flex;
  flex-direction: column;
  overflow: auto;
  height: 100%;
  width: 100%;
}

This container holds both the content and the footer, allowing it to have the scrollbar instead of the content itself. Unfortunately, the issue eludes me.

html,
body,
#app {
  padding: 0;
  margin: 0;
}
#app,
#appContainer {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
#header {
  background-color: #dddddd;
  width: 100%;
  min-height: 36px;
  height: 36px;
  display: flex;
  flex-direction: row;
}
#contentContainer {
  display: flex;
  flex-direction: column;
  overflow: auto;
  height: 100%;
  width: 100%;
}
#content {
  display: flex;
  flex-direction: column;
  flex: 1;
}
#footer {
  display: flex;
  flex-direction: row;
  background-color: #dddddd;
  height: 20px;
  min-height: 20px;
  width: 100%;
}
<div id="app">
  <div id="appContainer">
    <div id="header">Header</div>
    <div id="contentContainer">
      <div id="content">
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
      </div>
      <div id="footer">Footer</div>
    </div>
  </div>
</div>

Check out the demo on JSFiddle.

Answer №1

Give this method a try, it may be just what you're searching for

Take a look at this code snippet on JSFiddle

html, body, #app
{
  padding: 0;
  margin: 0;
}

#app, #appContainer
{
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#header
{
  background-color: #dddddd;
  width: 100%;
  min-height: 36px;
  height: 36px;
  display: flex;
  flex-direction: row;
}

#contentContainer
{
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
  height: 100%;
  width: 100%;
}

#content
{
  display: flex;
  flex-direction: column;
  flex: 1;
}

#footer
{
  display: flex;
  flex-direction: row;
  background-color: #dddddd;
  height: 20px;
  min-height: 20px;
  width: 100%;
}

Answer №2

I have attempted modifying the attributes of contentContainer such as changing width to min-width and flex-shrink to 0:

html,
body,
#app {
  padding: 0;
  margin: 0;
}
#app,
#appContainer {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
#header {
  background-color: #cccccc;
  width: 100%;
  min-height: 36px;
  height: 36px;
  display: flex;
  flex-direction: row;
}
#contentContainer {
  display: flex;
  flex-direction: column;
  overflow: auto;
  width: 100%;
  min-height: calc(100vh - 36px);
}
#content {
  display: flex;
  flex-direction: column;
  flex-basis: auto;
  flex-grow: 1;
  flex-shrink: 0;
}
#footer {
  display: flex;
  flex-direction: row;
  background-color: #cccccc;
  height: 20px;
  min-height: 20px;
  width: 100%;
}
<div id="app">
  <div id="appContainer">
    <div id="header">Header</div>
    <div id="contentContainer">
      <div id="content">
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
      </div>
      <div id="footer">Footer</div>
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the correct way to retrieve the location offset of a specific DOM element?

As I attempt to determine the offsets of an element utilizing element.getBoundingClientRect(), a challenge arises when the webpage is extensive in vertical length and involves scrolling. The function then provides me with the offsets of the element relat ...

What steps can be taken to make sure padding impacts all lines, not just the first one?

I have added padding to a span of text using Bootstrap. However, the issue arises when the text goes to the next line using < br > - the padding for that line and beyond disappears. Here is the specific code causing this problem: <div class="col ...

Change the CSS menu item to directly load the website instead of using javascript to replace a placeholder

I have a CSS navigation menu, but I'm facing an issue. When I click on a link in the menu, like Google for example, it only changes the name of the placeholder and doesn't actually load the page. Any suggestions on how to fix this? Thank you for ...

Guarantee that unique events are triggered following h5validate events

I am currently experiencing a problem with H5Validate where its events are overriding the custom events I have implemented, causing my events not to trigger because they are based on H5validate events. To work around this issue, I have resorted to setting ...

Ng-Zorro nz-range-picker resizing issue on smaller mobile screens

Currently using ng-zorro-antd 7.0.0 rc3 alongside angular 7.2.4. Encountering an issue where horizontal scrolling is not possible on mobile browsers when using the nz-range-picker. It appears that the element is too large for the screen, even though the p ...

Enhance the spacing between the UL-LI navigation menu and the currently selected item

I'm struggling with adjusting the spacing between items in my navigation menu, specifically the li elements that are currently too close together. I've attempted to increase the margin-left within the .main_menu li CSS rule, but it doesn't s ...

Flipboard-inspired CSS Animation

I have been following a tutorial regarding CSS flip effects and encountered some challenges. The tutorial can be found here. .flip-container { perspective: 1000px; } /* add more code here... */ <div class="flip-container" ontouchstart="th ...

Issue with displaying fonts from @font-face on 000webhost

I recently set up my own website. Originally, I was using webs.com as my hosting provider, but they started adding an ad bar to their html-only hosting which I didn't like. So, I switched over to 000webhost. However, after moving everything to 000webh ...

observing numerous directories in Sass

Is there an efficient way to monitor multiple directories in sass using a shell script? This is what I currently have in my shell script: sass --style compressed --watch branches/mysite/assets/css/sass:branches/mysite/assets/css & sass --style compre ...

What is the best way to handle PHP-generated content using Jquery?

I have a PHP script that is responsible for generating a list element for each entry in a MySQL database. My goal is to utilize the jQuery :odd selector on these list elements in order to change the background color of every other element. Unfortunately, t ...

Icon appearing outside the button instead of inside

Here's a button I'm working with: <button class="glyphicon glyphicon-option-horizontal" (click)="myFuncion()"></button> Recently, I updated my bootstrap library from version 3 to 4.2.1 and now the icon is no longer visible. I' ...

How to customize the appearance of an HTML checkbox using custom images for a unique

Does anyone know how to change the default style for: <input type=checkbox...> I want it to use my own styled pictures instead of the default style. Can anyone help? Thank you! ...

Troubleshooting a Jquery issue: change event not functioning

I have a dropdown menu with 2 options (Local/Import). Each option corresponds to a specific table that should show on the page when selected. However, I've tried using jQuery's change function but it's not functioning as expected. Instead of ...

Create a dynamic dropbox using JavaScript/JQuery in an HTML page

I am currently working on implementing 3 different drop down boxes that are triggered by 4 different buttons. These drop down boxes should appear within the #apple div. When Button B1 is clicked, the drop down options include Apple, Mango, and Papaya. Whe ...

Incorporating blur.js into an AngularJS project

Attempting to create a blurred background effect with Angular on a div, similar to the image above. I am using blur.js and it works well with jQuery. My main question is, can this be achieved with AngularJS and what is the best approach? I am new to Angul ...

Bootstrap forms with checkboxes and lineup labels

Here is the HTML code that has been generated: <div class="form-group"> <label class="control-label col-md-2" for="IsWebSiteActive">Website Active</label> <div class="col-md-4"> ...

Steps for Deactivating HTML Links

I am facing an issue with a link button inside a <td> that needs to be disabled. It is working fine on Internet Explorer but not functioning properly in Firefox and Chrome. I have tried various methods, but nothing seems to work on Firefox (using ve ...

A specific div remains in place as the user scrolls

Imagine a div that is positioned 60px from the top of the screen. What if, as you scroll down, it stops when it reaches 10px from the top and remains there for the rest of your scrolling session? And then, when you scroll back up, it goes back to its ori ...

Selenium typically only returns a portion of the script tag's content when using InnerText and InnerHTML

Seeking to automate front-end tests for a client's webpage in Selenium (java), I am faced with the challenge of extracting data from within the <script></script> tag in the provided HTML. <html> <head>...</head> <body& ...

For my website's navigation bar, I utilized Bootstrap 4. Despite my efforts, I encountered difficulty in modifying the background color of the enclosing div element

After experimenting with a few different options such as setting the background-color to transparent, rgba(0,0,0,0), and background: none; I found that when I used background-color: red or any other color, the color changed as expected. Below is the HTML ...