Is there a way to make sure a div always remains fixed at the bottom of a webpage, regardless of the amount of content?

I have been struggling to keep my footer at the bottom of the page, regardless of its size. However, whenever another div encroaches on the space, it gets moved around. I want it to be displayed over the other content, but since that content needs to be scrollable due to its size, this becomes a challenge. Here is the code snippet:

Check out the fiddle

.footer {
background-color:#FFF;
width: 100%;
border-top: 1px solid #ccc;
padding-top: 1em;
height: 140px; 
display: block;

.about {
font-family: HindMedium;
font-size: 13px;
min-width: 800px;
text-align: left;
width:100%;
min-height: 100%;
margin-bottom: -140px; 
    }

Answer №1

To fix the floating issue, ensure to add clear:both; to the .footer tag.

(function() {

  var img = document.getElementById('container').firstChild;
  img.onload = function() {
    if (img.height > img.width) {
      img.height = '100%';
      img.width = 'auto';
    }
  };

}());
* {
  margin: 0;
}

html,
body {
  height: 100%;
}

.footer,
{
  height: 140px;
  display: block;
}

p {
  font-family: HindRegular;
  font-size: 13px;
  font-weight: normal;
  display: block;
  ...
}
...

Answer №2

Make sure to omit these elements from your .about class. It's important to experiment with margin for better results. The current approach you are using is ineffective.

min-height: 100%;  
margin-bottom: -140px;

Include clear:both; in your styling for the footer.

Additionally, modify the body style attribute from height to min-height to allow the body to extend beyond the browser window size.

Answer №3

To ensure that floats are contained within the .about and .footer containers, you can apply overflow: hidden to them. The negative margin on the .about is unnecessary. If you wish to keep the footer at the bottom of the page even with minimal content, consider positioning it absolutely. Here's an example provided below, where everything is wrapped in a .wrapper container.

.wrapper { min-height: 100%; position: relative; }
.article { overflow: hidden; }
.footer { overflow: hidden; position: absolute; bottom: 0; }

With less content, the footer remains at the bottom: https://jsfiddle.net/johndoe/u4coohpp/1/

Even with more content, the footer continues to stay at the bottom: https://jsfiddle.net/johndoe/u4coohpp/3/

If you prefer elements to protrude from the .article and .footer containers or seek another approach, consider using inline-block instead of floats with vertical-align: top. Ensure to add * { box-sizing: border-box; } or adjust padding to margin.

https://jsfiddle.net/johndoe/u4coohpp/4/

Furthermore, prevent the email address from overflowing into adjacent columns by applying the following CSS rule to the footer:

.footer a[href*="mailto"] {
    word-break: break-all;
}

For a fixed footer implementation, refer to this example: https://jsfiddle.net/johndoe/gv7Lg3e0/1/

.footer {
    position: fixed;
    bottom: 0;
}

Answer №4

If you're looking to keep an element fixed at the bottom of the page while allowing content to scroll underneath, use position:fixed.

To update your footer styling, make these changes:

.footer {
  background-color: #FFF;
  border-top: 1px solid #ccc;
  padding-top: 1em;
  height: 140px;
  display: block;
  overflow: hidden;
  position: fixed;
  left:0;
  right:0;
  bottom:0;
  clear:both;
}

With this CSS, the footer will stay pinned at the bottom. Don't forget to add a spacer after the footer to enable proper scrolling functionality.

Include this in your HTML:

<div class='footer-spacer'></div>

In your CSS file, define the footer spacer like this:

.footer-spacer {
    height: 160px;
}

Also, remember to remove these lines from your .about class. Negative margins can lead to unwanted effects by moving elements off the screen.

min-height: 100%;  
margin-bottom: -140px;

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

Encountering an issue with Javascript while hovering over an element in a grid layout

After multiple attempts, I am still unable to determine why the text only appears when hovering over the last two product-cards in this grid layout. The preceding two cards display the text only when hovering over a specific area within the card, and the o ...

When the nav menu toggler in Bootstrap 4 is clicked on a mobile screen, it causes the content to

When I view this on xs or sm screens and click on the navbar toggler, it pushes all the content, including the header where the toggler is located, down the page to accommodate the dropdown menus. This behavior seems to be different from Bootstrap 3 and Bo ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Is there a method to trigger the DOM style change hook without using asynchronous code?

We have learned that css animation/transition does not work with display: block&display: none; therefore, I attempted to use someDom.style.transition = '0.3s' someDom.style.display='block' someDom.style.opacity=1 to create an anim ...

Overlap of sub menus

Seeking assistance from a CSS expert for a challenge I am facing. I am currently working on a toggle menu for mobile view, and encountering issues with the submenu. Any list item placed below another one with children is not visible. Removing the parent l ...

Incorporating a full-height website into another website for seamless integration

I'm attempting to embed a website within another website using an Iframe. I've successfully loaded the page, but now I need the embedded site to adjust its height according to the actual content on that site, not just the height of the container ...

"Utilizing Bootstrap to create a space-saving table layout with an

Using Bootstrap on a table causes an unexpected empty column to appear on the right side (as shown in the screenshot). This issue is strange because it works fine with another table using the same setup... but this particular table seems to have a mind of ...

Switch the background image of one div when hovering over a different div

Can anyone assist me with creating an interactive map where continents light up as you hover over them? I am using multiple images within div elements in order to achieve this effect. Specifically, I want to change the background image of one div when hove ...

Arrange two images next to each other using Bootstrap grid system

Struggling to replicate the design of this website: Fister. But unfortunately, my images are not aligning properly. <html> <head> <meta charset="utf-8"> <!-- CSS only --> <link href="https://cdn.jsdeli ...

Styling X and Y axis font color in charts using JavaFX 2.x CSS

Is there a way to change the font color of both X and Y axes? In my search through the css reference for fonts, I only found properties like font-size, font-style, and font-weight. font-size, font-style and font-weight I attempted to use -fx-font-color ...

Using Jquery and CSS to add a class with a 1-second delay when the mouse enters

I have successfully implemented the addClass function in my code, but I'm encountering issues when attempting to use delay or setTimeout functions. It's important to note that I'm avoiding the use of webkit attributes in CSS. If anyone has ...

Dealing with pesky table cell padding issues in Chrome

Struggling with table cell paddings in Chrome because it appears that if a table cell doesn't have pure text, the padding isn't applied. Here's my code: <table> <tr> <th></th> <th ...

Mastering the Art of Resizing Video Controls: A

https://i.stack.imgur.com/jTgap.png https://i.stack.imgur.com/Exf6Y.png On the initial screenshot, the video player displays normal controls. However, on the same website with identical CSS, the second video player shows different control settings. // C ...

Tips for utilizing CSS to ensure that the images within a hyperlink are consistent with the desired proportions

Seeking assistance with adjusting image proportions in a href link. Despite using background-position, background-size, and object-fit properties, the pictures inside the link are not matching the proportions on different devices. Any help would be greatly ...

CSS Dilemma: Font Refusing to Change

Hey everyone, I'm new to web development and currently building a basic website on my computer. However, I'm facing an issue where the font I want to use is not changing. Both my HTML and CSS files are located in the correct folder and I am confi ...

Encountering a challenge in developing a personalized, digital keyboard with CSS grid in React where some buttons are not appearing on the screen

Attempting to develop an on-screen keyboard for a React application using CSS grid to partition the containing element. Despite setting the necessary display properties and grid template, only 4 buttons are appearing, with most of them hidden below one ano ...

Modify the color of the text to be white

How can I modify the code below to change the text color to white? The original code is inspired by this question. I am unsure about how the text color was originally set to blue. .footer-background { padding-top: 20px; padding-bottom: 20px; bac ...

Tips for managing table scroll in a flexbox design

Check out the demo here I am working with a table that has an indefinite number of rows and columns. When the table has a small number of rows and columns, it adjusts its width according to the available page space minus the width of the sidebar. Everythi ...

Please ensure that any accompanying text is positioned solely underneath the image, and not interspersed

In my design, I have a div box containing both an image and text. My goal is to ensure that the text only flows under the image if the display resolution is smaller than a certain threshold. Check out this draft to get a better understanding: ...

Issues with background image slideshow functionality

For one of my websites, I am using a theme that originally came with a single background image. I modified it to have multiple background images for the 'section' tag <section id="intro" class="intro"></section> U ...