The Content Finds Complete Coverage in the Absolute Footer

After setting up a position absolute footer, I noticed it starts covering the content whenever more content is added.

I would like the footer to always stay at the bottom of the page, even if there isn't enough content to push it down



Check out the Live Code

   <div id="wrapper">
       <div id="header"></div>
       <div id="content"></div>
       <div id="footer"></div>
    </div>

CSS

#wrapper{
  position: relative;
  min-height: 100%;
}
#content{
  width: 900px;
  margin-top: 20px;
}
#footer{
  width: 100%;
  height: 140px;
  position: absolute;
  bottom: 0;
}

Answer №1

While I can't say for sure if this is the exact solution you're seeking, it may provide some assistance. To ensure that your footer remains at the bottom of every page, regardless of the content's length, you will need what is commonly referred to as a "sticky" footer. There are various methods available online, but here is one approach which involves knowing the height of your footer div.

Start by removing your footer div from the wrapper and placing it after the closing div tag that corresponds to #wrapper. Then, add the following CSS properties: padding-bottom: 140px; box-sizing: border-box; to the #wrapper selector in your stylesheet. It's crucial that the padding value matches the height of your footer. The box-sizing property ensures that the padding doesn't increase the total height, preventing unnecessary scrollbars unless needed.

Next, eliminate position: absolute; bottom: 0; clear: both; from the #footer selector - these are no longer necessary. Instead, include margin-top: -140px;

Lastly, confirm that the following rules are included in your CSS: body { height: 100% } html { height: 100% }

This method aims to prevent any overlap between the footer and content, ensuring the footer always stays at the page's bottom unless additional content pushes it further down.

Answer №2

Finding the perfect solution in this case can be a bit tricky, especially considering the impact of the content within #content.
Based on the code provided, it seems that the main issue lies in the lack of height defined for your body element.
The majority of included div elements are positioned outside the normal flow using fixed or absolute positioning.

To address this, I would suggest adding the following to your CSS:

body{height: 100%;}

This adjustment should help ensure that your footer stays at the bottom of the page.

UPDATE

If you want to guarantee that your footer appears below #content, you can explicitly set its position relative to the bottom of the page like so:

#footer{top: 100%; bottom: 0;}

Additionally, you can add some top margin to the footer as well:

#footer{top: 100%; bottom: 0; margin-top: 20px;}


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 it possible to use jquery to specifically target classes?

I am trying to achieve the following: $('.class.img').css('cellpadding', variable); However, this code does not seem to be working as expected. Despite searching online, I have not been able to find a solution. Any assistance on how to ...

What is the process for integrating SAP BO objects into HTML containers?

Has anyone successfully integrated a SAP BO object into an HTML container? I'm looking to embed a dashboard directly onto my webpage instead of redirecting users to a new tab for the Business Objects platform. ...

Restrict the number of button clicks to only once every 5 minutes

Similar Question: jquery disable a button for a specific time I am currently developing a PHP-based website. One of the features I want to implement is a button that can only be clicked once every five minutes by the user. After some research, I hav ...

Obtaining the weight of a webpage using Selenium Automation_Framework

Currently, I am in the process of creating performance-related tools for web pages within a Selenium framework designed for .NET systems. With a focus on page performance, I am specifically analyzing page load time and page weight. In order to measure th ...

CSS Class ID selection for selectpicker

I have two classes: selectpicker with different IDs: selected_Test_Platforms and selected_SIL_relevant I am trying to assign a preselection from an array called "availableTestPlatforms" to the selected_Test_Platforms. Currently, when I use the selector $( ...

What could be causing the onclick function in the button tag to malfunction?

I have implemented a feature where clicking on a "Delete Photo" button would trigger the appearance of another delete button in the code. The code for this functionality is as follows: <button type="button" class="btn btn-danger" onc ...

Unique ways to serialize an HTML element efficiently: JavaScript tricks

Is there a way to store a reference of an HTML tag for future use? For instance, if I click on a div and save a pointer to that div in JavaScript, is it possible to serialize this pointer and then de-serialize it to use in another part of the web applicat ...

What is the reason behind the inability to overflow the Safari viewport?

My website, , has a footer that is clickable in Chrome but not in Safari. When users scroll to the footer in Safari, the screen jumps back to the top, making it inaccessible. Can anyone help me identify the issue? Below is the CSS code for my React projec ...

Pay attention to the input field once the hidden attribute is toggled off

In attempting to shift my attention to the input element following a click on the edit button, I designed the code below. The purpose of the edit is to change the hidden attribute to false. Here's what I attempted: editMyLink(i, currentState) { ...

Customize the CSS styling of third-party components in different pages using NextJS

When working with third-party components, you can include their styles by importing their stylesheet into your component or _app.tsx file. For detailed instructions on how to do this, you can refer to Next.js documentation. Another option is to add the sty ...

What is causing my Fabric.js canvas to malfunction?

Here is the link to my JSFiddle project: http://jsfiddle.net/UTf87/ I am facing an issue where the rectangle I intended to display on my canvas is not showing up. Can anyone help me figure out why? HTML: <div id="CanvasContainer"> <canvas id ...

Dompdf is outputting the HTML Bootstrap code as col-sm-x instead of col-lg-x

Currently, I am utilizing Dompdf in my PHP project to generate PDF reports. However, I have encountered an issue where the HTML bootstrap code does not render as expected on the PDF document. Specifically, when viewing the grid on a smaller device, it coll ...

Darken the backdrop of the bootstrap modal

When the modal is opened, the background turns black instead of having an opacity of 0.5 or something similar. How can I resolve this issue? I am using Bootstrap 3.2. Below is some CSS code snippet: .fade.in { opacity: 1; } .modal-open .modal { overflow ...

Issue with Rendering Rapheal Pie Chart in Internet Explorer 9

I encountered an issue in IE9 where I received the error message "SVG4601: SVG Path data has incorrect format and could not be completely parsed" while trying to draw a pie chart on an HTML5 page using Raphael JS and SVG. The problem arose when the "d" att ...

Automatically adjust the size of embedded video streams within DIV elements

My application is quite simple, it displays four video streams in a quadrant layout. Users can double click on each video to switch to full-screen mode and then again to go back to the quadrant view, which all works perfectly. The issue I'm facing in ...

Which target should be specified for pressing Enter in a Javascript Alert using Selenium IDE?

Seeking assistance with creating simple test cases using Selenium IDE. Encountering difficulties when recording test cases involving Javascript alerts, as Selenium does not support these pop-ups. Attempted a workaround by simulating the Enter key press wh ...

CSS3 variables causing issues

I want to streamline my CSS file by setting up generic variables that can be used throughout to ensure consistency and organization. For example: @shadow: 6px 6px 10px rgba(0,0,0,0.2); .shadow { box-shadow: @shadow inset; } However, when I try to a ...

Add a captivating backdrop to a div element

So I have this unique HTML element that showcases a large headline with two decorative lines on either side, extending to the full width of the element. However, I now have a requirement to display some text as a background behind this element. The issue ...

Having trouble with Tailwind CSS not functioning correctly once the font is imported?

I am currently working on a next.js project and utilizing tailwind for styling. I have noticed an odd behavior when importing a custom font into my globals.css file. page.jsx "use client"; import React from "react"; const page = () = ...

The Transition Division Is Malfunctioning

I've encountered an issue where I am trying to move a div by adjusting its left property, but no transition is taking place. Regardless of the changes I make to my code, the result remains the same. Below is the current state of the code. Can anyone i ...