Struggling to keep the footer anchored at the bottom of the page

When the content on an HTML page is minimal, the footer may end up positioned halfway up the page, creating a blank space below. This can be unappealing, especially on larger screens. Designers are frequently tasked with moving footers to the bottom of the viewport, but accomplishing this isn't always straightforward.

The structure of my HTML looks like this:

<html>
  <body>
    <div class="wrapper">
        ....
    </div>
    <div class="footer" id="cdFooter">
        .......
    </div>   
  </body>
</html>

I attempted to follow advice from the Internet by setting the CSS rules as follows:

html,body {
    position: relative;
    min-height: 100%;
}

.wrapper {
    min-height:100%;
    position: relative;
    overflow:hidden !important;
}
.footer {
    bottom: 0;
    width: 100%;
}

(Additional CSS rules can be found at the URL below, as there's limit for code here.)

Despite implementing these rules, the footer still does not reach the bottom of the browser on large desktop screens. The result can be viewed at the following URL:

Someone suggested adding a rule to the wrapper like margin-bottom: **px, but that did not resolve the issue on my site.

Could someone kindly review my URL and suggest a solution? I prefer a responsive design without using fixed heights to push elements down.

Thank you.

If I use position: absolute, it will override the wrapper. Adding body {height: 100%} also proved ineffective. Can anyone attempt to make edits on my URL?

In my opinion, the key problem lies in making the body height equal to the browser height, similar to how it is defined in html. Hopefully, this approach could solve the issue.

Answer №1

Your footer display and body element height were not clearly defined in your request. To ensure proper placement, please update your CSS code as follows:

body {
    height: 100%;
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
}

Answer №2

In order to fix the position, you need to remove it from the normal flow and make adjustments in the footer section.

position: absolute;

If you want more control options, consider adding:

top:

This will allow you to manage the height of the footer effectively.

One reason for the overlapping issue may be due to the lack of a specified height in your wrapper, causing it to overlap since the height is not defined and starts from the top.

Another approach would be to define absolute positioning on the wrapper as well, using top and bottom properties to regulate the height.

It is advisable to remove the min-height attribute from all properties as it might disrupt other block elements.

min-height: 100%

Give this a try:

.wrapper {
    position: relative;
    overflow: hidden
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
}

For an example with absolute positioning on both wrapper and footer, check out this link.

Instead of focusing on "body height being 100% of browser height", consider attaching the footer at the bottom regardless of body or browser height. This approach ensures that the footer remains fixed at the bottom regardless of different browser dimensions.

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

The icon displays correctly in Firefox but is not visible in IE

link REL="SHORTCUT ICON" HREF="/images/greenTheme/favicon.ico" type="image/x-icon" While this code functions properly in Firefox, it appears to be causing issues in Internet Explorer. Can anyone provide guidance on how to resolve the compatibility issue w ...

Arranging the data in the table by alternating rows using Datatables

I need to organize my data in a way that includes an additional row for descriptive information, but this particular row should not be sorted. It is crucial for understanding the rest of the data, so hiding or showing it is not an option. Is it possible t ...

Having trouble changing the Font Awesome icon on click?

I'm struggling to figure out why I can't change a font awesome icon using a toggle. I've tried various solutions but nothing seems to be working. Any insights on what might be causing this issue? (HTML) <span class="toggle-icon" ...

A flashy Rickshawgraph with the ability to modify the background color of the top data series

I am facing a challenge in modifying the background color of the rickshawgraph widget in dashing based on the maximum value of the highest graph from the latest incoming data. While I have successfully implemented this feature for one series, I am struggli ...

Instructions on adding a solid border color to a circular div using CSS

Hey there! I'm curious, is it possible to style a straight border color on a rounded div using CSS? Here I have some basic Tailwind CSS code. <div class="rounded-2xl w-72 h-20 border-l-4 border-l-yellow-500"> ... </div> In the ...

Tips for passing values and their corresponding labels during a click event in Angular 4

When I click the plus button, I want to hide the li element. Even though the data is passing correctly, the li element is not clearing as expected. The desired outcome is for the li instance to be removed once the plus button is clicked. https://i.stack.im ...

What's the best way to use JavaScript to obtain the width of a 'css-pixel' based on a media query?

While there have been discussions on how to determine device sizes using media queries like Twitter Bootstrap, I am looking for a reliable way to achieve the same output using JavaScript. Specifically, I want to get the CSS media query pixel number rather ...

Stylesheets per module in Angular 2

For my website design, I've decided to adopt a modular structure using sass. To ensure consistency throughout the module, instead of defining stylesheets at the component level, I plan to define them at the module level and import them into each compo ...

What is the best way to modify this CSS code for use in a React Native

Encountering an issue while trying to apply this CSS property in a React Native project. border-radius: 50% / 100%; Attempting the following: borderRadius: '50% / 100%' An error message is displayed stating "Java.lang.string cannot be cast to ...

HTML5 audio recording

I have been exploring different methods to record audio using HTML5, but so far I have not found a solution. I attempted to utilize this particular example without success. It seems that the statement about lack of support from any browser may be true. ...

CSS transformation on the go

Can anyone help me? I am trying to create an animation for a hamburger menu when checked and unchecked. I have managed to animate the menu, but I'm struggling with animating the left menu when transforming it to 0. &__menu { transform: transla ...

Ways to display an icon in Angular 10 only when it is hovered over

Just getting started with Angular and still learning the concepts. Trying to figure out how to show an icon only when it's hovered over. Can anyone assist me? Sorry, can't share the code because of company rules. The icons are for sorting and ...

best practices for creating space between flexbox items

My task involves presenting a continuous scroll list of scheduled jobs using Angular Material. Each item in the list needs to be divided into three columns utilizing flexbox. Despite my efforts, I am struggling with adding space between the columns within ...

When using jQuery and AJAX, the functions each, if, post, and .html work properly but occasionally erase data inexplicably

I have a PHP page containing FedEx and UPS tracking numbers stored in a MySQL database, which are displayed within DIVs with the class "trackingnumber". Using JavaScript, I loop through these divs to retrieve the ID and then send it to a PHP page that fetc ...

How can JavaScript be used to rearrange the placement of DOM elements?

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div class="boxes"> <div class="red" style="width: 300px; height: 300px; color: red"></div> <div class="blue ...

The appearance of all input forms in MaterializeCSS when used in an electron environment appears to

After following the instructions here on how to get started with Materialize CSS, I am having issues with my input form appearing strange: The contents of my current index.html file are as follows: <!DOCTYPE html> <html> <head> & ...

What could be causing my HTML element to vanish once the animation is complete?

I have successfully implemented an animation on 3 HTML elements for a landing page I am currently developing. The animations are working as intended, but I am facing an issue where the two lower elements (an h1 tag and a button) briefly appear on the page ...

Display the remainder of an image's height within a div container

Here is the code snippet I am working with: HTML: <div id="mapWrapper" style="height: 624px;"> <div class="box" id="map"> <h1>Campus</h1> <p>Description Campus Map.</p> <img src="abc.png" ...

Custom background options for Wordpress developer

I have been exploring the WordPress codex to learn about incorporating custom background options, similar to this example $defaults = array( 'default-color' => '', 'default-image' => '&apo ...

What is the best way to align the navigation with a maximum of three elements (lists) in a row using responsive design?

I've been trying various methods but haven't been able to center it while keeping the padding intact. It's a mobile navigation bar. Here is what my code is producing currently: [1]: This is how I want it to appear: [1]: Thank you in advan ...