What is the best way to ensure that Bootstrap sticky footer content stretches to full page height?

Utilizing a Boostrap sample, I've successfully created a sticky footer for a website using CSS. The footer remains at the bottom of the page even as it is resized. However, on certain pages, there is content that needs to be displayed nearly full-page while still excluding the footer. Thus, the content section must be set to 100% height so its contents can occupy the entire height.

I have provided a JSFiddle to illustrate the issue.

How can we ensure the green container div reaches full height, touching the top of the page and the top of the footer simultaneously?

Thank you!

<div id="wrap">
    <!-- Begin page content -->
    <div class="container">
        <div class="page-header">
            <h1>Sticky footer</h1>

        </div>
        <p class="lead">This is the sticky footer template taken from the Bootstrap web site.</p>
        <p class="lead">How can we make this green .container div the full height of its parent #wrap div?</p>
    </div>
    <div id="push"></div>
</div>
<div id="footer">
    <div class="container"></div>
</div>

#wrap .container {
    background-color: lightgreen;
}
/* Sticky footer styles  */
html, body {
    height: 100%;
    /* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    /* Negative indent footer by it's height */
    margin: 0 auto -60px;
}
/* Set the fixed height of the footer here */
#push, #footer {
    height: 60px;
}

#footer {
    background-color: #f5f5f5;
}

Answer №1

I have successfully resolved your issue by transferring it from JSFiddle to codepen, as I prefer the functionality of codepen over other platforms. Here is the link for reference:

The solution I provided was sourced from the following link, where a thorough explanation can be found:

Upon implementation, I discovered that height: auto !important; is causing a delay in the desired outcome. By commenting out this line in the #wrap id, you will observe the changes taking effect. The code pen showcases additional alterations for better understanding. To achieve the desired result from your original query, the following adjustments are necessary:

#wrap .container {
    background-color: lightgreen;
    min-height: 100%;
    height: auto;  /* this adjustment resolves the "excess content problem" */
}


 html, body {
    height: 100%;
    background-color: #dedede;
    padding: 0;
    margin: 0;
}


 #wrap {
    min-height: 100%;
    /* height: auto !important; */
    height: 100%;
    margin: 0 auto -60px;
}

An alternative approach would involve removing the entire line containing !important instead of merely commenting it out like so:

#wrap {
    height: auto !important;
    /* revised to */
    height: auto;
}

To enhance clarity, I made some color adjustments to emphasize the underlying process. These modifications are visible in the codepen alongside detailed commentary reflecting my actions.

Additionally, I encountered an issue with the sticky footer contributing to excess scrolling due to margin settings. This was rectified with the following amendment:

margin: 0 auto -60px;
/* updated to */
margin: 0 auto -80px;

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 CSS Blend Mode alternative for Internet Explorer?

I've implemented the background-blend-mode on this element: <a href="#" class="blend"> <h3>Title</h3> <p>Content goes here</p> </a> It's all set up with a background-image url. When the element with c ...

What is the best way to stop a Primefaces knob label from appearing outside of the knob circle while scrolling horizontally?

Currently employing Primefaces 13, I've encountered an issue with a dataTable that contains a column displaying a number using the p:knob component. When horizontally scrolling the dataTable, the label of the knob component is rendered outside the kno ...

The LINK CSS within the HTML code serves no purpose on the internet? Everything is working perfectly

Everything works fine in the development environment, but not online. The website URL is: The CSS URL: Both URLs can be accessed. However, the CSS file seems to have no effect. Any idea why? Thank you in advance! Additional Info: I am using nginx as a ...

The jQuery toggleClass() function is not being applied successfully to content that is dynamically generated from

I've created an awesome collection of CSS-generated cards containing icons and text with a cool animation that expands upon tapping to reveal more icons and options. I carefully crafted the list to look and behave exactly how I wanted it to. But now, ...

Having difficulty extracting the values of td elements from a table in HTML string using PHP's XPath parser

From a Wikipedia page, I have the html snippet below... <table class="wikitable"> <tbody> <tr> <td>mod_access</td> <td>Versions older than 2.1</td> <td>Included by Default</td> </tr ...

What is preventing my accordion from closing completely?

I'm currently working on creating FAQ questions in an accordion format. However, I've encountered an issue where adding padding around the answer section prevents the accordion from closing completely. Removing the padding solves the problem, but ...

Use PHP to open a text file and display its contents in a textarea

I have a textarea on my website and I'm trying to figure out how to populate it with the content of a text file. I followed a tutorial that guided me through writing some code, but when I implement it, I'm facing an issue where the words from the ...

Arrangement of elements on a page

I may not be an HTML pro, but I'm curious to find out how I can determine if one element is near another in a web page. For example, how can I tell if a div is close to another div, or if a table is adjacent to an image or another table? ...

Animating a Bootstrap 4 card to the center of the screen

I am attempting to achieve the following effect: Display a grid of bootstrap 4 cards Upon clicking a button within a card, animate it by rotating 180 degrees, adjusting its height/width from 400px - 350px to the entire screen, and positioning it at the c ...

Leveraging trustAsHTML with an array of object elements

I'm facing a challenge in passing an array of objects from an Angular Controller to the ng-repeat directive. The objects within the array have multiple properties, some of which may contain HTML that needs to be displayed using the ng-repeat. I' ...

Strategies for Preserving Added Field Data Using JQuery

I am working on a code that dynamically adds fields to a form, you can see it in action on this jsFiddle. My question is, is there a way to keep the newly added fields even after the form is submitted and the user returns to the page? I'm not looking ...

Customize CSS in Razor/Sitecore

We are seeking a solution for our component that includes a background image, requiring it to be loaded through CSS. Our front-end developer prefers using background: url(/*path here*/).... The proposed solution involves retrieving the image path from Site ...

IOS Troubleshooting: Ineffectiveness of the Transform

So I am encountering a slight issue while trying to incorporate this code on iOS because I am not familiar with how iOS operates. On my website, I have implemented a circle that works perfectly fine on browsers and Android devices. However, when it comes t ...

How to prevent click events and still enable scrolling within a DIV using CSS/JS

Basically, I am looking to enable scrolling within a DIV while also disabling click events. Any suggestions on how this can be achieved? Appreciate any help! ...

I am looking to switch the input border-bottom color to blue when the input field is focused or has valid content

Can someone help me change the border bottom color of my input to blue in the following HTML code: .inputBox input:focus ~ input, .inputBox input:valid ~ input{ border-bottom: 1px solid #0000cd; } <div class="i ...

_my_custom_styles.scss are being overridden by reboot.scss

Hey there, I'm currently facing an issue where my custom CSS is getting overwritten. Even though I have placed my custom CSS beneath the CDN bootstrap reference, it doesn't seem to resolve the problem. For instance, when attempting to change the ...

Can the border become fainter and then more pronounced when hovered over?

Does anyone know of a simple method to create a fading effect for a CSS border-bottom when hovering over an image, and then have the border fade out once the hover is removed? <div class="hover"> <img src="images/ex.jpg"/> </div> ...

Error: Unable to locate module 'next/font/google/target.css'

After setting up Next.js version 14.0.1 on Node.Js v20.9.0 and Ubuntu 20.04, I encountered an error right from the start. Failed to compile /var/www/html/C#/nextApp/app/layout.js Module not found: Can't resolve 'next/font/google/target.css?{&quo ...

Implementing Angular with HTML progress bar for interactive client-side features

Exploring the integration of HTML built-in progress bars with Angular: <label for="file">File progress:</label> <progress id="file" max="100" value="70">30%</progress> I am curious about how ...

Display loader until the document body has finished loading

Many developers have shared solutions for displaying a loader while an element is being loaded. However, my challenge is unique. I want to display a loader before the document body is fully loaded. The issue arises from an AJAX call in my code: var url = ...