Troubleshooting Flexbox Sticky Footer: Issue with 'Flex: 1' not properly filling the height

Currently experimenting with the flexbox sticky footer technique to create a dynamic-height footer, which has been a challenge for me. However, I'm facing an issue where the main section does not expand to fill the entire height of the window even after applying 'min-height: 100vh' and 'flex-direction: column' to the body container.

As a result, the footer remains halfway up the page, and I'm unsure why this setup isn't functioning properly despite my research on the topic.

HTML:


    <body>

    <div id="wrapper">

        <main>

            <div id="pageContent">

                <h1>Page Content</h1>

                <h2>Page Content</h2>

                <h3>Page Content</h3>

                <h4>Page Content</h4>

            </div>

        </main>

        <footer>

            <row>

                <p>Footer Content</p>

                <p>Footer Content</p>

                <p>Footer Content</p>

                <p>Footer Content</p>

            </row>

        </footer>

    </div>

</body>

CSS:

html, body
{
margin: 0;
padding: 0;
max-width: 100%;
background: #1a1a1a;
}

body
{
display: flex;
min-height: 100vh;
flex-direction: column;
}

main
{
width: 100%;
margin: 0;
padding: 50px 10%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
flex: 1;
}

main > #pageContent
{
height: 100%;
width: 100%;
margin: 0;
}

footer
{
height: auto;
background: #0d0d0d;
padding: 0 10%;
margin: 0;
}

footer > row
{
display: flex;
}

footer > row > p
{
flex-grow: 1;
flex-basis: 0;
text-align: center;
padding: 25px 0;
margin: 0;
}

Answer №1

Make sure to add display:flex to the #wrapper element.

Remember, flexbox properties are not inherited.

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
}
body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
#wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}
main {
  width: 100%;
  margin: 0;
  padding: 50px 10%;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  flex: 1;
}
main > #pageContent {
  height: 100%;
  width: 100%;
  margin: 0;
}
footer {
  height: auto;
  background: lightgreen;
  padding: 0 10%;
  margin-top: auto;
}
footer > row {
  display: flex;
}
footer > row > p {
  flex-grow: 1;
  flex-basis: 0;
  text-align: center;
  padding: 25px 0;
  margin: 0;
}
<div id="wrapper">

  <main>

    <div id="pageContent">

      <h1>Page Content</h1>

      <h2>Page Content</h2>

      <h3>Page Content</h3>

      <h4>Page Content</h4>

    </div>

  </main>

  <footer>

    <row>

      <p>Footer Content</p>

      <p>Footer Content</p>

      <p>Footer Content</p>

      <p>Footer Content</p>

    </row>

  </footer>

</div>

Check out this Codepen Demo

Answer №2

Get rid of the 'wrapper'..

<content>
    <container id="pageContent">

        <h1>Page Content</h1>

        <h2>Page Content</h2>

        <h3>Page Content</h3>

        <h4>Page Content</h4>

    </container>
</content>
<footer>
    <row>

        <p>Footer Content</p>

        <p>Footer Content</p>

        <p>Footer Content</p>

        <p>Footer Content</p>
    </row>
</footer>

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

Is there a way to nest my form within another form and utilize just one submit button for both?

<form action="<?php $self ?>" method="post"> <h2>LundaBlogg</h2> <div class="fname"><label for="name"><p>Namn:</p></label><input name="name" type="text" cols="20" onkeyup="En ...

Conceal anchor links using jQuery by targeting their title attribute

Looking at the html below <li class="static"> <a title="blog" class="static menu-item" href="http://google.com">Blog</a> </li> <li class="static"> <a title="profile" class="static menu-item" href="http://profile.com"> ...

Adjusting the dimensions of a rectangle using jQuery: A step-by-step guide

I am encountering an issue while attempting to adjust the width and height of a rectangle using jQuery. The error message I receive is "Uncaught TypeError: Cannot read property 'scrollWidth' of null" Below you can find the code snippet in questi ...

Guide on adding space between rows in a table using HTML and Bootstrap 5

In the current table containing my content, it appears like this: https://i.sstatic.net/Mm7qT.png. I wish to add space between each row to create distinct separation and achieve a look similar to this: https://i.sstatic.net/ARgR1.png I experimented with ...

Creating responsive HTML page text and table with the use of JavaScript

Trying to create a responsive webpage has been a bit challenging. I experimented with height,style.height, style.OffsetHeight, etc. but still struggling to dynamically make a square table. Although the code below changes the height, the table's width ...

Having trouble with input event listeners in JavaScript?

I've been attempting to trigger the keyup event using EventListener for an input tag, but it doesn't seem to be working and I'm unsure why. Here is the code I have: document.getElementById("ajax").addEventListener("keyup", function() { ...

Issue with Dropzone not functioning correctly within Vue transition modal

I've implemented a dropzone function in the mounted function, which works perfectly when the dropzone is outside of a modal in the view. However, when I try to use it within a modal with a transition effect, it doesn't work. Any suggestions on ho ...

Organizing semantic elements at the beginning of a column

I am facing a challenge with formatting a long text into 2 columns while also including a fixed height table in one of the columns. The goal is to have the table at the top of the 2nd column without splitting the text or using JavaScript. The table shoul ...

What is the best way to ensure the checkbox functions correctly in this specific situation?

I am utilizing PHP, Smarty, and jQuery in the development of my website. Currently, I am working on implementing checkboxes within a Smarty template. Below is a snippet of my Smarty code related to checkboxes: <table cellpadding="5" cellspacing="0" bor ...

Automatically filling in related information in multiple input fields after choosing a value in a specific input field using JavaScript

My horizontal form is dynamically generated using JavaScript, with each input field having a jQuery autocomplete that retrieves data from a database using the $.get method. I'm looking to automatically populate the second input field with the corresp ...

Creating a JavaScript function for a custom timed traffic light sequence

Currently, I am facing a challenge with my high school project of creating a timed traffic light sequence using JavaScript for my upcoming exams. Unfortunately, I feel quite lost and unsure about how to proceed. My initial plan involves formatting the valu ...

Issues arise when trying to use jQuery within an AJAX-loaded div on the same page

I have been struggling with this issue for days and have tried looking up solutions online, but haven't had any luck. I attempted changing a '.live' to '.click' in the code, but that didn't work either. In the jquery.ajaxy.js ...

What is the best way to define the relative path and folder paths in HTML and CSS when working in Visual Studio 2012?

Working on a basic HTML project that includes css and javascript. Within the project folders named css, scripts, and images are used for organization. The project structure can be seen in the provided image. https://i.sstatic.net/OwCSL.jpg The issue that ...

Ways to showcase a website within an HTML document using a URL?

Is it possible to show 2 webpages on a single aspx webpage? For instance, When a user opens the link for www.mywebsite.com, I would like to display both www.google.com and www.bing.com on my homepage. Behind the scenes, I will call two separate URLs an ...

Incorporating a .jar file into HTML (for remote controlling a Raspberry Pi)

In my current project, we are working on remotely controlling a toy car using two Raspberry Pis (one in the car, one in the remote control). The setup is operational at this point, allowing the remote control to drive the car using a touch display. We hav ...

How can I alter the image using the success function in jQuery?

I'm encountering an issue with my jQuery voting script. Everything seems to be working correctly, except for the fact that the image in the success function of the AJAX request is not updating as expected. jQuery: $("a.vote_down").click(function(){ ...

Struggling with developing a chrome extension

I have successfully developed a Chrome extension that, when clicked, says hello world. However, I am facing an issue with creating a simple button that triggers an alert when pressed. Could it be due to the inclusion of JavaScript in an HTML extension file ...

Display the CSS dropdown menu as a block`

I've been attempting to design a dropdown menu. My goal is for the anchor tag to display when hovered over. I understand that using display:block won't work when the 'a' is not part of the block, but I'm unsure how to proceed. Any ...

Differences in typography across Mozilla Firefox and Internet Explorer

I have come across a question that seems quite common, yet unsolvable. However, I will give it a try anyway. Take a look at this image: To view a larger version of the image, visit the following URL: https://i.stack.imgur.com/dddNm.jpg HTML code: <d ...

Concealing the TinyNav Drop-Down Menu

Currently, I am utilizing TinyNav on my website and it is working wonderfully. However, due to our extensive menu system, the tinynav dropdown appears quite large. I have been attempting to figure out a way to hide all sub-menus without success. I experim ...