Tips for creating a fixed footer that adjusts with a flexible wrapper

Feeling incredibly stressed, I embarked on a quest to find the perfect sticky footer.

After searching Google for what seemed like an eternity, I came across multiple tutorials recommending the use of min-height:100%. However, this approach caused the wrapper to look unattractive and lose its dynamic height when the content was smaller than the window.

This led me to ponder: Is there a way to create a sticky footer without sacrificing the dynamic nature of the wrapper?

Answer №1

Discover an ingenious JavaScript technique that enables you to create a sticky footer that remains at the bottom of the window when the content is smaller than the window. When the content exceeds the window height, the footer automatically adjusts to the bottom of the page!

setInterval(function(){
    var wrapper_height = $('#wrapper').height();

var window_height = $(window).height();
    if(wrapper_height<window_height){
        $('footer').css({position:'absolute', bottom: '0px'});
    }else if(wrapper_height>window_height){
        alert('switched to mode 2');
         $('footer').css({position:'relative', bottom: '0px'});
    }
},10);



$('#wrapper').click(function(){

    $('#wrapper').append('<p>BLAH</p>');

}) 

Trust this solution proves beneficial to you!

Answer №2

When you mention keeping the wrapper dynamic, are you referring to the main content area as opposed to the footer section? Is it specifically the height of the footer that needs to be adjustable, or is it more about the overall page height?

If the footer has a fixed height but you want the main content area to be able to vary in size, I recommend checking out this helpful resource:

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

Adjust text alignment dynamically as a div changes size with CSS in ASP.NET

For the menu bar on my site, I utilized flex containers and nested div elements. Currently, all text is aligned at the center. However, when the website is viewed on smaller devices and it resizes, I would like the text to be aligned to the left. Is there ...

Click here to get the button click link

Is there a method to obtain the link of a button click on a website? This is the Website and it features a play button. I am looking for a way to capture the link triggered by clicking the play button so that the audio starts playing automatically each t ...

The conflict arises when importing between baseUrl and node_modules

I am currently working on a TypeScript project with a specific configuration setup. The partial contents of my tsconfig.json file are as follows: { "compilerOptions": { "module": "commonjs", "baseUrl": &quo ...

Create a dynamic onClick event script and integrate it into Google Optimize

I need to incorporate a button element into my website using Google Optimize for an experiment. This button needs to trigger a specific script depending on the variation of the experiment. I have attempted two different methods: <button id="my-button" ...

Tips on incorporating the Browserified npm package into an Angular controller

After spending countless hours searching for a solution to integrate Browserify with my project, I found myself struggling to find a tutorial or example that addressed my specific issue. Most resources focused on bundling code rather than demonstrating how ...

Error: Preflight request returned a 405 HTTP status code when querying Ionic + CI backend

I am currently working on my first app using ionic with a codeigniter backend. However, I am encountering the "Response for preflight has invalid HTTP status code 405" issue in ionic + CI backend. Can anyone help me solve this problem? This is my controll ...

Could you please explain the output of the offset function in jQuery?

After reviewing the code, I am struggling to comprehend the output of the offset function: $(document).ready(function() { $('#goto-show-form').click(function() { $('html, body').animate({scrollTop: $("#show-form").off ...

JointJS: I need to extract the source value from the JSON text with the ID field

I need to extract the text value from "source":{"id": using JSON data in this specific JavaScript object : { "cells": [ { "type": "devs.Model", "size": { "width": 40, "height": 40 }, "inPorts": [""], "outPorts": ["" ...

What sets apart using 'self.fn.apply(self, message)' from 'self.fn(message)', and what are the advantages of using the former method?

Whenever I come across code that looks like thisnewPromise.promiseDispatch.apply(newPromise, message), I can't help but wonder why they didn't simply use newPromise.promiseDispathch(message) ...

How to retrieve the IP address of a client using Node.js within a setInterval loop

Working on a project utilizing nodejs to fetch client IP Addresses. Within the setinterval function, I have set up the following code: var countdown2 = setInterval(function(){ async function baked(req, res, id){ var getIP = req.headers['x-forward ...

Execute the "organizeImports" trigger through the terminal in TypeScript

One feature of VSCode is its editor capability to organize and clean imports in javascript and typescript files upon saving ( "source.organizeImports": true ). Inquiry Is there a way to trigger this action on a file using the command line? Something alo ...

Issue arising from changing classes in Internet Explorer

I've encountered an issue where I am trying to change the class of an element on a mouseover event, but it doesn't seem to fire as expected. However, when I add an alert in the function, it suddenly works. Here is the code that doesn't work ...

Emphasize cells and headers when a cell's value deviates from its initial value

I implemented cell editing in my primeng table. Here is the code: <div class="card"> <p-table [value]="products" dataKey="id" [tableStyle]="{ 'min-width': '50rem' }"> <n ...

Leveraging Expressjs to act as a proxy for handling cross-origin requests made via AJAX

I'm working on a website that relies entirely on external APIs, without any server-side logic. All data will be retrieved from an external API. The backend server is mainly used for asset management and routing. We've decided to use nodejs with e ...

Streamlining Complex Javascript IF Statements

I came across a suggestion online for making an if statement more concise: if([1,5,7,22].indexOf(myvar)!=-1) alert('yeah') Instead of the longer version like this: if( myvar==1 || myvar==5 || myvar==7 || myvar==22 ) alert('yeah') Is ...

css - Tips for reducing the speed of inertia/momentum scrolling on mobile devices

I have been working on creating a scrollable card gallery using a CSS grid layout. The structure I am following is similar to this: <div class="gallery-wrapper"> <div class="gallery-container"> <div id="card-1" class="gallery-ca ...

How to implement saving TypeScript Map() in Firebase Cloud Functions?

I am currently developing a Firebase Cloud Functions application using TypeScript that is designed to save an instance of Map() to Cloud Firestore. The map consists of user IDs as keys and objects with 2 simple attributes as values. Due to the dynamic natu ...

Displaying JSON data dynamically by iterating through it in a loop

While working with JSON data in a loop, I noticed that the code quality does not meet my expectations. I have a feeling that I might be missing something in my approach. $(function(){ $.getJSON('data.json', function(data){ let content ...

Deactivate any days occurring prior to or following the specified dates

I need assistance restricting the user to choose dates within a specific range using react day picker. Dates outside this range should be disabled to prevent selection. Below is my DateRange component that receives date values as strings like 2022-07-15 th ...

Traversing JSON data structures regardless of missing keys

Here is a JSON containing some data: { "results":[ { "name":"Sydney Showboats", "photos":[ { "photo_reference":"Pic062" } ] }, ...