Positioning the CSS footer at the bottom of the webpage

I'm trying to keep a footer at the bottom of the page by setting a DIV with min-height:100% and another DIV for animating ajax content loads.

Here is how I set it up in HTML:

<div class="main">
    <div class="header navi>…</div>
    <div class="animater">
        <!-- content here -->
        <div class="footer">
            <!-- footer content here -->
        </div>
    </div>
</div>

And here is my CSS setup:

.main {
    min-height:100%;
    margin-left:auto;
    margin-right:auto;
    position:relative;
}
.header {
    // height, width, margin, position
}
.animater {
    // empty
}
.footer {
    bottom:0px;
    position:absolute;
}

Initially, when the content is smaller than the screen, everything looks good. The footer stays at the bottom as intended. However, when I animate the "animater" using CSS keyframes, things go awry. After the animation ends and I replace the content, sometimes the footer ends up at the top of the "animater". But if I manually reload the page (without animations), the footer stays properly positioned.

What I really need is a footer that always sticks to the bottom of the content, regardless of its height. Setting min-height on the "animater" doesn't work because it's not at the very top of the page.

Answer №1

This demonstration showcases the essential CSS required to ensure a footer remains at the bottom of a webpage. View the example here

The HTML structure:

<div class="wrapper">
<div class="page">
    Insert content here
</div>
<div class="footer">
    Content for the "footer" section Goes Here
</div>
</div>

The corresponding CSS styling:

/* NECESSARY CSS TO KEEP THE FOOTER AT THE BOTTOM */

html, body{
height:100%;    /* ensures .footer stays at the bottom */
margin:0;   /* eliminates scroll bar caused by (100% + default margin) */
}

.wrapper {
min-height: 100%;   /* maintains position of .footer at bottom */
position: relative; /* must be relative else .footer will overlap content */
}

.page {
padding-bottom:2.2em;   /* padding at bottom is crucial to avoid .footer overlap */
}

.footer {
position: absolute; /* secures .footer at the page's bottom */
bottom: 0px;    /* ensures .footer remains at bottom */
height:2em; /* height should be less than .page's bottom padding */

}

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

Exploring ways to animate a conditionally displayed component when the state changes using a combination of javascript and css

I am encountering a scenario where I have a react component with a specific part that is rendered conditionally. Upon clicking on a visible element within the component (button), the state changes triggering the display of the hidden parts. However, inst ...

Having trouble getting two form fields to align horizontally in CSS

I am trying to arrange two form fields side by side horizontally, but I am having an issue where the second field is slightly lower than the first field. I am currently using display:inline-block in the CSS to achieve the horizontal alignment. Below is th ...

Text not aligning properly when utilizing the <p> tag

I'm struggling to align my text in a row, as shown below: https://i.sstatic.net/SGQ8I.png "Investup" and "Real estate" should be aligned. I need to move the "Real estate" paragraph so that it aligns with the "invest up" paragraph. Here's my co ...

Using jQuery to toggle the menu

I've been brainstorming ways to add a toggle menu on my website and finally stumbled upon a solution that works great! http://jsfiddle.net/hhcsz5cr/ <div> <h1><button class="button" data-circle="travel"> <i cl ...

Customizing form designs with the combination of Django and Bootstrap

After developing a basic purchase form with custom fields, I conducted a test to ensure its functionality. The form rendered successfully, as shown below. <form id="category_form" method="post" action="/purchase/"> {% csrf_token %} { ...

What is the best way to eliminate leading zeros in PHP when echoing SQL statements?

Being a front-end programmer on a team of three, my PHP/MySQL skills are fairly basic. However, our back-end programmer is going on vacation and we have a deadline to address a minor visual detail. Currently, we are working on a page that displays multiple ...

Angular neglects the specified animation timing

I created a sidebar component that relies on the sidebarExpanded state passed through Input(). Despite the correct animation trigger upon input change, the width adjustment happens abruptly. Interestingly, the same animation code works flawlessly in anothe ...

Looking for a solution to indent the start of each stanza in Google Blogger since it automatically removes <p> tags

Here's a recurring issue that has been brought up before, but I'm not here to discuss inserting <p> tags. Imagine you're using the Google Blogger "Compose" editor and have this text: Lorem ipsum dolor sit amet, consectetur adipiscing ...

Setting dynamic image dimensions within a div element

Is there a way to display the div width in percentage even when the image is not loaded? The image sizes are mentioned in percentage and they load dynamically, making it impossible to fix their size. How can we ensure that the div maintains the correct wid ...

Is it necessary to set up Tailwind CSS for each new project we start?

Is it necessary to install Tailwind CSS and its files for each new project in every new directory? I'm uncertain if this is the correct process, or if there is an alternative method available. Furthermore, when making changes to files on a live serve ...

css align center issue

<div id="headermain"> <div id="logo"> <a href="#">net</a> </div> Having trouble centering the #logo div within #headermain. Even with margin:auto; applied, the #logo div remains off-center. #headermain i ...

Using a `right: 0` value will not be effective when using absolute positioning

Currently, I am in the process of developing a website utilizing Bootstrap 3.3.6. After going through a tutorial on how to create a responsive banner slider, I found this resource helpful: http://www.jqueryscript.net/slider/Full-Width-Responsive-Carousel- ...

Balanced padding for a harmonious interior and exterior presentation of elements in CSS

In my Bootstrap row, I have placed two images with 6 columns each. My goal is to have the same margin between these two images as the margin between the images and their parent element. I attempted to add margins/padding to the images, but found that addi ...

Transitioning from one CSS id to another during page loading

Wondering how to fade in one CSS id on page load and then smoothly transition to another after a few seconds? Here are the ids: #background { background: url("images/am_photography_bg.jpg") no-repeat center -25px fixed; background-size: 100%; ...

Allow only the modals that do not have a particular parent class to be dragged

I am currently working on making all the modals draggable on my website. However, there are certain modals with a class of .fullscreen that I do not want to be draggable. The issue I'm facing is that I can't figure out how to exclude the modals ...

Uncertainty surrounding the application of class selector within CSS

Currently, I'm deep into my CSS learning journey on Progate.com. I've been cruising through the exercises, but I hit a roadblock when it comes to a specific class selector in the CSS code. The task at hand is simple: I need to tweak the CSS so th ...

What are some ways to style an image that has been added using JavaScript using CSS?

I utilized a JavaScript function to add an image, which looked like this: function show_image(src) { var img = document.createElement("img"); img.src= src; document.body.appendChild(img); } But when I attempt to change its style using CSS: img ...

enhance the brilliance of elements at different intervals

My latest CSS animation project involves creating a stunning 'shine' effect on elements with a specific class. The shine effect itself is flawless, but having all elements shine simultaneously is making it look somewhat artificial. I've bee ...

The dimensions are out of control with tailwind

I've recently come across Tailwind and I'm trying to adjust the size of a simple div. However, it seems that something is not working as expected. What could be the issue here? Can someone explain why Tailwind is not maintaining consistent width ...

Inadequate text alignment

Trying to create a header mockup for a website featuring branding elements like a logo and brand name. Utilizing Angular.js for the webpage development process, incorporating a URL for the logo image from an online source. Encountering alignment issues th ...