The footer fails to adhere to the bottom of the page

Struggling to keep my footer at the bottom of the page when there is minimal content. I attempted using:

position:absolute;
and
bottom:0;

It appears to stay in place, but when more content is added, it ends up going "under" the footer that remains near the center of the page.

When I say "under," I mean the text flows beneath the footer and overlaps with it. If necessary, I can provide images showcasing the issue. Thank you for your time!

This is the HTML code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/src/app/footer/footer.component.css"> <!--import css footer-->
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
</head>
<body>
<footer class="footer">
    <div class="flex-wrapper">
     <div class="container">
        <div class="row">
            <div class="footer-col">
                <div class="content"> 
                    <a href="#"> <img src="https://i.imgur.com/1yvwx9I.png" ></a>
                </div>
            </div>
            <div class="footer-col">
                <h4>Company</h4> 
                <ul>
                    <li><a href="about-us">About Us</a></li>
                    <li><a href="contact">Contact Us</a></li>
                    <li><a href="#">Placeholder</a></li>
                    <li><a href="#">PlaceHolder</a></li>
                </ul>
            </div>
            <div class="footer-col">
                <h4>Help</h4>
                <ul>
                    <li><a href="faq">FAQ</a></li>
                    <li><a href="deliveries">Deliveries</a></li>
                    <li><a href="return-policy">Return Policy</a></li>
                    <li><a href="privacy-policy">Privacy Policy</a></li>
                </ul>
            </div>
            <div class="footer-col">
                <h4>Follow Us</h4>
                <div class="social-links">
                    <a href="facebook"><i class="fab fa-facebook-f"></i></a>
                    <a href="twitter"><i class="fab fa-twitter"></i></a>
                    <a href="instagram"><i class="fab fa-instagram"></i></a>
                    <a href="linkedin"><i class="fab fa-linkedin-in"></i></a>
                </div>
            </div>
        </div>
     </div>
    </div>
  </footer>

</body>
</html>


This is the CSS code

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body  {
  line-height: 1;
  font-family: 'Poppins', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Rest of the CSS styles remain unchanged */

Here's the result when adding bottom:0px;:

Answer №1

If you want to ensure your footer always stays at the bottom, try using a flexbox for the body tag.

Here is an example of HTML & CSS Code Snippet:

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

body  {
  /* font size and family */
  line-height: 1;
  font-family: 'Poppins', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* keeps the extended footer without spaces on the sides */
html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}

.content {
  flex-direction: column;
}

.footer {
  flex-shrink: 0;
}

.container {
  width: 100%;
  margin: 0 auto;
}

.row {
  display: flex;
  flex-wrap: wrap;
}

ul {
  list-style: none;
}

.footer {
  background-color: #24262b;
  padding: 20px 0;
}

.footer-col {
  width: 25%;
  padding: 0;
}

.footer-col h4 {
  font-size: 25px;
  color: #ffffff;
  text-transform: capitalize;
  margin-bottom: 35px;
  font-weight: 500;
  position: relative;
}

.footer-col h4::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: -10px;
  background-color: #e91e63;
  height: 2px;
  box-sizing: border-box;
  width: 50px;
}
...

You have the freedom to add a header above or more content below. Using flexbox technique allows either:

  1. Setting flex: 1 on the child element to expand and fill the available space (the content).
  2. Using margin-top: auto to separate the child from its neighboring elements as much as possible.

For more sticky footer options, you may refer to this article "https://css-tricks.com/couple-takes-sticky-footer/".

You can also view the Codepen demonstration here.

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

Steps to ensure that a particular tab is opened when the button is clicked from a different page

When I have 3 tabs on the register.html page, and try to click a button from index.html, I want the respective tab to be displayed. Register.html <ul class="nav nav-tabs nav-justified" id="myTab" role="tablist"> <l ...

The <hr> element creating a line beneath a connected div

Currently, I am in the process of designing a website with three main divs all on one page. To visually separate these divs, I have included a subtle horizontal line. The horizontal line between the first and second div looks correct as intended. However ...

What is the best way to create a line break in a flex div container to ensure that overflowing items wrap onto the next line using

Using material-ui popper to display a list of avatars. Trying to arrange the avatars horizontally within the popper. <Popper style={{ display: 'flex', maxWidth: '200px', }}> <div style={{ marginRight: '20px' }}&g ...

Having trouble with CSS Locator identifying an element in your Protractor Test?

In the Protractor test snippet below, I am attempting to calculate the quantity of div elements using the CSS locator: let list = element.all(by.css('div[class="ag-header-cell ag-header-cell-sortable"]')); expect(list.count()).toBe(11); ...

What is the best way to update a div element without the need for double clicking?

Let me explain this clearly. Currently, I have a table displaying in HTML when called. However, I want the table to disappear and show filtered results when someone enters a president's name and clicks on "Search for Presidents". I attempted using a c ...

Switching from vertical pills to horizontal tabs for smaller screens

I have a vertical pills menu that looks great on large screens, but takes up too much space on small screens. Is there a way to switch it to a horizontal tab layout for smaller screens? I tried searching online for examples but couldn't find any. < ...

Does the height of the rendered font adjust based on the length of words in Japanese formatting?

I can't figure out why this strange issue is occurring... It seems that the font "size" (or rather, the height it occupies) changes depending on the length of a word. I tried to reproduce this in English without success, but it consistently happens w ...

Stylish slanted divs achieved using Bootstrap 4

I'm currently in the process of constructing a block with 6 slanted divs using Bootstrap. Take a look at the image provided below: https://i.sstatic.net/vvg0b.png After attempting to use rows and columns, I noticed that they weren't aligning co ...

Switch up the box-shadow color with ColorThief!

Is there a way to adjust this script to change the box-shadow color of #player1? <script type="text/javascript> $(window).ready(function(){ var sourceImage = document.getElementById("art"); var colorThief = new ColorThief(); var color = ...

"Enhance your Vue.js application with the powerful capabilities of vue3-easy

I am currently working on a Vue.js project utilizing the "vue3-easy-data-table" library and following the style recommendations outlined on this particular webpage: Despite attempting to apply the following CSS properties: --easy-table-body-even-row-font ...

Using IMG HTML tags in PHP embedded within JavaScript code

Is there a way to successfully add an IMG src tag in JavaScript to pass the image source to a JavaScript variable 'content' and then have it passed to a PHP variable '$html'? I've attempted this but keep encountering an 'unide ...

The Firefox browser is not fully displaying the button background

Having an issue with a button that doesn't completely fill up on Firefox only. Here's the problem in action: This is how it should actually look: Not quite sure what to do. Here's the CSS styling being used: .button-panel .button { -web ...

Is there a way to extract all the aria-label attributes from elements that share a common class?

I am currently working on a program that tallies the number of reactions from Facebook posts, with each reaction stored in an aria label containing detailed information. I am encountering difficulty retrieving the values of these unique aria labels due to ...

"I'm experiencing a problem with display:inline in IIS 7 - can anyone

Unfortunately, our development web server cannot be accessed externally, so sharing a link is not possible. However, I can explain the issue we are experiencing. While creating markup for a new website on my local machine, everything appears as intended. ...

changing the css transformation into zoom and positioning

My goal is to incorporate pinch zoom and panning using hardware-accelerated CSS properties like transform: translate3d() scale3d(). After completing the gesture, I reset the transform and switch to CSS zoom along with absolute positioning. This method ensu ...

DjangoPDFViewer

I need help figuring out how to integrate a PDF Viewer into my Django website. Right now, I'm using an iframe to show the PDF, but I want to add annotation functionality directly on the site. I've looked into using PDF.js, but it means incorporat ...

Including hyperlink tags within a CSS file

Can you create internal links within a CSS file, like inserting a table of contents at the top where you can click on an item and immediately jump to that section in the CSS file similar to an anchor tag? This feature would be extremely handy for long CSS ...

Exploring the Power of Nested *ngFor in Angular 2

I am struggling with passing indexes to a function where the first parameter (ii) is coming back as undefined. <div *ngFor="let tab of screen.data.tabs; let indexTab = i;"> <div *ngIf="tab.active"> <div *ngIf="tab.questions"&g ...

Column Alignment Problem in Bootstrap

I'm currently working on a blog template project that resembles the design of this particular page However, I've encountered an issue with aligning the grids in a way that meets my requirements. To showcase my problem, I have shared my version o ...

Is CSS unit pt recommended for styling UI elements?

Currently developing UI controls and deliberating whether to utilize pt for dimensions like widths, heights, border sizes, margins, paddings, and font sizes. Preference is for resizable controls that maintain consistency across various screens and projecto ...