CSS for the footer at the bottom of the page

Check out this fiddle where I am trying to create a footer that remains at the bottom of the page, similar to the screenshot provided:

However, I'm facing an issue where when the browser window is resized so that the viewport is smaller than the content area, and the page becomes scrollable, the footer ends up in the middle of the page instead of staying below the content. Once scrolling occurs, the footer aligns itself with the middle of the content boxes, as shown in another screenshot:

Is there a way to achieve a footer that sticks to the bottom of the viewport when no scrollbar is present, but then moves to the bottom of the content boxes once scrolling becomes necessary due to content extending past the viewport?

Currently, I am utilizing position:absolute; bottom:0; on the footer. Should I be adding additional properties to my content box or footer? Any guidance would be greatly appreciated!

Answer â„–1

If you're looking to achieve this using CSS, there have been numerous attempts with various hacks and workarounds. However, the simpler solution often involves using Javascript. But if you prefer a pure CSS approach, here's a typical strategy:

1) Begin by setting * to border-box:

* {
    -webkit-box-sizing:border-box;
    -moz-bos-sizing:border-box;
    box-sizing:border-box;
}

2) Next, designate your footer to position:absolute with a fixed height:

#footer {
    position:absolute;
    left:0;
    right:0;
    bottom:0;
    height:40px;
}

3) Ensure that html, body, and your container all have a height of 100%, minimum height of 100%, and set your container's position to something other than static. Also, add padding-bottom to accommodate your footer height plus any desired gap:

html,body,#container {
    height:100%;
    min-height:100%;
}

#container {
    position:relative;
    padding-bottom:50px;
}

This setup should function adequately for IE8 versions and newer. Handling compatibility with IE7 and below can prove to be quite challenging—additional research may be required in those cases. A couple of key points to remember:

  1. The box-sizing declaration is crucial for ensuring that the height of 100% takes padding into account.
  2. When employing position:absolute on a child element, the parent must have a position value other than static to establish the child's positioning relative to the parent. Otherwise, the position will default to the nearest ancestor with a non-static position (which could be the window).

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

Having trouble changing the color of the active icon in Material UI stepper

I am running into an issue with changing the color of the highlight class when using react material ui. https://i.sstatic.net/1lxTs.png CSS stepIcon: { '&$active': { color: '#1e88e5', }, }, < ...

Can text automatically adjust its size based on the browser's dimensions using CSS?

Can text automatically resize as the browser size decreases for liquid-based design using percentages? While images and divs can rescale, text scaling in percentages seems impossible! When set in percentages, it only changes the unified em setting for tha ...

Problem encountered with a selection menu

I'm experiencing some trouble with the dropdown menu. Whenever I try to move the mouse to access the dropdown menu, it seems unresponsive. I attempted adjusting the padding on a line of code but ended up moving the entire line instead. Here is the cod ...

Is there an issue with margin parsing in Firefox 9 for Mac?

I'm encountering a strange issue with my current project. The #head div appears to have the margin-top CSS property enabled, even though it isn't actually set. This problem only seems to occur in Firefox 9.0.1 (Mac); other browsers display it cor ...

Utilizing Javascript to implement a tooltip feature for dynamically inserted text

I recently incorporated a brief jQuery tooltip plugin into my site. It consists of approximately ten lines of code and works smoothly, as demonstrated in this demo. However, I encountered an issue when attempting to add new text that should also trigger t ...

Strange anomaly occurs when resizing and blurring an image on Chrome

I've been experimenting with a CSS effect that combines zooming and blurring. The idea is that when I hover over an image, it should blur out and scale slightly, all while being contained within a div with overflow:hidden. However, when testing in Ch ...

Revamp the sequence of divs using jQuery

<div class="example first">111</div> <div class="example second">222</div> <div class="example third">333</div> Can the order of these divs be changed using jQuery? I am looking to get: <div class="example second"&g ...

Create a fully responsive introduction page with three columns using Bootstrap, ensuring that the height of the

Currently, I am in the process of designing a website for a restaurant, hotel, and vineyard. My goal is to create three separate websites that are linked through one introductory page. The concept for the intro page involves three columns displayed side b ...

What causes the size of an image to decrease when placed within an anchor tag?

Trying to add clickable social media icons, but when wrapped in an anchor tag the images shrink significantly. <span class="iconspan"> <a href="https://www.instagram.com/lil_ijoez/" target="_blank" ...

What steps can be taken to address issues with the counting system in a lootbox opening

I am currently developing a virtual loot box simulator and have encountered a challenging issue. My goal is to track the quantity of Normals, Legendaries, Epics, and Rares obtained by the user. However, I am facing a problem where instead of updating the c ...

icon from font-awesome changes color when hovering over

My ASP.NET gridview control includes a font-awesome trash icon in the last column. I'm trying to make the icon change color to red when I hover over it, and then revert back to its default color when I move my mouse away. Here is the code for the te ...

How can I eliminate or override the CSS property from a content delivery network (CDN)?

Currently, I am utilizing swiper.js through a CDN. However, there seems to be an issue in the swiper-bundle.min.css CDN file where the .swiper-button-next and .swiper-button-prev classes are set to top:50%; like so: .swiper-button-next, .swiper-button-prev ...

"Implemented a user-friendly header and footer that stick to the top and

My goal is to create a fixed header and footer, allowing the main content to scroll underneath while keeping the right navigation in place. To achieve this effect, I've been experimenting with different solutions. One of my attempts can be viewed her ...

Adjusting column width in Bootstrap grid when content is missing

Currently, I am encountering a problem with the grid system while attempting to create a kanban style drag and drop system. The issue is illustrated in the image below. Each card should be positioned according to the arrows shown. As the 2nd column is cur ...

CSS styling doesn't take effect until the page is reloaded due to the failure of cssText

After generating a new list item, it appears that the CSS styling is not being inherited until the page is reloaded. Even though I have added styling using cssText dynamically, it doesn't seem to be working as expected. I've attempted using cssT ...

Ways to create space between rows

Here is some code structure that I'm working with: .col_1_6 { width: 70%; float: left; } .col_1_4 { width: 30%; float: left; } .row-content { clear:both; padding-bottom: 105px; } <div class="row-content"> <div ...

Tips for maintaining an open sub menu while hovering over a link

I'm currently working on a navigation menu using jQuery that includes categories, subcategories, and their subsequent subcategories. However, I am facing some issues with it not functioning as intended. To avoid cluttering this space with excessive HT ...

External CSS stylesheets fail to function properly in the presence of the Bootstrap framework

I'm experiencing an issue where my external stylesheet isn't being compiled when I include bootstrap. Strangely, it works fine with internal and inline stylesheets. However, when I switch to Firefox browser, it works perfectly. What could be caus ...

The transition effect does not seem to be functioning properly within the mobile menu on a React JS application utilizing styled

My goal is to create a mobile menu that slides in from the right side when the button is clicked. While the sliding animation works well, the opening and closing of the menu happen abruptly without any transition effect. Upon inspecting the elements, I can ...

Identifying rectangular shapes in an image and overlaying a div on top using Jquery

I am currently exploring the possibility of achieving the following: Imagine having an image within a div (serving as the background image). This image resembles an Excel sheet. My goal is to generate an input tag or contenteditable div when a user clicks ...