Tips for positioning the footer at the bottom of the page

During the process of constructing a new website, I included a footer that is neatly positioned at the bottom of my screen.

However, I noticed that on pages with minimal content, the footer does not remain fixed at the bottom:

In order to ensure that the footer is consistently displayed at the bottom of the screen, I made some adjustments to my CSS:

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

Although this adjustment placed the footer at the bottom, it did not stretch the background as desired.

Furthermore, when there is more content on a page, it ends up being displayed below the footer.

It appears that my current CSS modifications are inadequate. Can anyone offer suggestions for addressing this issue correctly?

Following changes recommended by Mehadi Hassan have resolved most issues, with the addition of:

body {
  display: flex;
  flex-direction: column;
  height: 100vh; /* To avoid IE 10-11 `min-height` bug */
}

Despite these improvements, a small error persists on one of the pages, although all div elements appear to be functioning correctly.

<?php require_once('includes/header.php'); ?>

    <!-- Page Background -->
    <div class="bg">

        <!-- Page Content -->
        <div class="container header">

          <!-- Page Heading/Breadcrumbs -->
          <h1 class="mt-4 mb-3">About Rotterdam Steel Works</h1>

          <!-- Intro Content -->
          <div class="row">
            <div class="col-lg-6">
              <iframe class="embed-responsive-item" src="img/media/RSW_web.mp4" allowfullscreen width="100%" height="100%"></iframe>
            </div>
            <div class="col-lg-6">
              <p>Rotterdam Steel Works is a steel cutting company equipped with two plasma and two oxyfuel cutting machines. We also offer Laser and Waterjet cutting services at competitive prices. Our reputation is built on fast delivery, good price-quality ratio, and efficient communication. Your orders are promptly passed to our AutoCAD technician for production planning, ensuring timely and high-quality results. For more information on our products and how Rotterdam Steel Works can be your reliable partner, please feel free to contact us.</p>
            </div>
          </div>
          <!-- /.row -->

          <!-- Team Members -->
          <h2 style="padding-top: 30px;">Contact Persons</h2>

          <div class="row">

            <div class="col-lg-3 mb-3">
              <div class="card h-100 text-center">
                <img class="card-img-top" src="img/gerard.png" alt="Gerard de Kaper">
                <div class="card-body">
                  <h4 class="card-title">Gerard de Kaper</h4>
                  <h6 class="card-subtitle mb-2 text-muted">Owner</h6>
                  <p class="card-text">Gerard has been working in the cutting industry since 1991. He started as a draughtsman and gained experience in production. His expertise lies in different types of steel and their specific properties.</p>
                </div>
                <div class="card-footer">
                  <div class="text-center"><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee9ebfceffceacefce1fafaebfceaefe3fdfaebebe2f9e1fce5fda0e0e2">[email protected]</a>"><button type="button" class="btn btn-primary"><i class="fas fa-envelope"></i> Send Email</button></a></div>
                </div>
              </div>
            </div>          

            <div class="col-lg-3 mb-3">
              <div class="card h-100 text-center">
                <img class="card-img-top" src="img/mohamed.png" alt="Mohamed Chahchouhi">
                <div class="card-body">
                  <h4 class="card-title">Mo Chahchouhi</h4>
                  <h6 class="card-subtitle mb-2 text-muted">Production Planning</h6>
                  <p class="card-text">Mohamed serves as our production planner and has been Gerard's colleague since 2001. He bridges the gap between your requirements and the production team, ensuring that orders are fulfilled exactly as specified.</p>
                </div>
                <div class="card-footer">
                  <div class="text-center"><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c61634c7e637878697e686d617f786969607b637e677f226260">[email protected]</a>"><button type="button" class="btn btn-primary"><i class="fas fa-envelope"></i> Send Email</button></a></div>
                </div>
              </div>
            </div>

            <div class="col-lg-3 mb-3">
              <div class="card h-100 text-center">
                <img class="card-img-top" src="img/battal.png" alt="Battal Ozturk">
                <div class="card-body">
                  <h4 class="card-title">Battal Ozturk</h4>
                  <h6 class="card-subtitle mb-2 text-muted">Workshop Manager</h6>
                  <p class="card-text">Battal is our hands-on supervisor who has been part of RSW since its inception. He ensures that your requests are fulfilled, serving as the link between all departments within the organization.</p>
                </div>
                <div class="card-footer">
                  <div class="text-center"><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b797a6f6f7a775b69746f6f7e697f7a76686f7e7e776c74697068357577">[email protected]</a>"><button type="button" class="btn btn-primary"><i class="fas fa-envelope"></i> Send Email</button></a></div>
                </div>
              </div>
            </div>

            <div class="col-lg-3 mb-3">
              <div class="card h-100 text-center">
                <img class="card-img-top" src="img/mark.jpg" alt="Mark Ruiter">
                <div class="card-body">
                  <h4 class="card-title">Mark Ruiter</h4>
                  <h6 class="card-subtitle mb-2 text-muted">Business Developer</h6>
                  <p class="card-text">Mark has played an integral role in RSW's growth since its establishment. Apart from managing the firm's ERP system, he possesses extensive market knowledge, enabling him to lead innovation within the industry.</p>
                </div>
                <div class="card-footer">
                  <div class="text-center"><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="670a06150c2715081313021503060a141302020b1008150c1449090b">[email protected]</a>"><button type="button" class="btn btn-primary"><i class="fas fa-envelope"></i> Send Email</button></a></div>
                </div>
              </div>
            </div>

          </div>
          <!-- /.row -->

        </div>
        <!-- /.container -->

    </div>
    <!-- /.background -->

    <?php require_once('includes/footer.php'); ?>

  </body>

</html>

Answer №1

Perhaps this solution could be helpful for you:

html {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh; /* Resolve the issue with IE 10-11 `min-height` bug. */
}
.content {
  flex: 1 0 auto;
  padding: 20px;
}
.footer {
  background: blue;
  flex-shrink: 0; 
  padding: 20px;
}
<div class="content">
  <h1>Sticky Footer with Flexbox</h1>
  <p>Text here...</p>
</div>

<footer class="footer">
  Footer 
</footer>

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

Adding multiple elements with varying content to a separate division

I am attempting to combine two div elements into a single div, but I'm encountering difficulties. Despite thoroughly examining my code, everything appears to be correct. Here's what I've tried so far. To assist me in achieving this, I am ut ...

Modify all the content within the DIV using Regex, while keeping the HTML tags intact

I am attempting to replace all the text inside a DIV, including within its children, without modifying any HTML tags. Specifically, I want to switch all instances of 'Hello' to 'Hi'. Thank you for your help. var changes = $('div ...

What is the most efficient method for updating URLs in CSS files before the website goes live?

The project I am currently working on has been worked on by various coders with different backgrounds. One of my recent achievements was writing a clean Capistrano recipe to minimize CSS and JS files. Now, the challenge ahead is figuring out how to identif ...

Employ CSS flexbox and/or JavaScript for creating a customizable webpage

I am in the process of developing a basic IDE for an educational programming language that has similarities to Karel the Dog. One major issue I am encountering is creating the foundation HTML page. The IDE consists of 4 main areas: Toolbox (contains but ...

Angular 6 CSS spacing dilemmas

We recently made the switch from Angular 5 to Angular 6 and noticed that there is no spacing between the buttons/icons, etc. We are looking to bring back the spaces between the buttons and icons. I have recreated the issue below. As you can see in the Ang ...

Infinite scrolling made effortless with jQuery and Ajax

I am attempting to create a basic infinite scroll feature that monitors when the user scrolls to the bottom in an HTML file. Once the bottom is reached, it should then load additional content from another HTML file which contains more text. The second HTM ...

What is the best location to integrate jQuery UI Bootstrap in a Rails project

In order to use Bootstrap and jQuery UI together in my application, I decided to integrate jQuery UI Bootstrap. Unfortunately, many of the gems that handle asset pipeline integration seem outdated, so I opted to manually download the CSS files and insert t ...

Is there a way to apply multiple colors to a h1 tag in HTML?

I need help with adding multicolor to a heading on my website using CSS. I am trying to define colors using the span element with different classes for each text section. However, the colors are not showing up as expected and there seems to be spacing issu ...

Creating an infinite scroll with a gradient background: a step-by-step guide

I am currently working on a project to develop an infinite scrolling webpage with a dynamic gradient background that changes based on the user's scroll position. While researching, I came across some code for infinite scrolling using time and date. I ...

What is the best way to conceal a dropdown menu when the page first loads?

I have a dropdown menu that is displaying like this: <ul> <li class="dropdown open"> <a aria-expanded="true" href="#" class="dropdown-toggle waves-effect waves-button waves-classic" data-toggle="dropdown"> <spa ...

Troubleshooting issues with CSS dropdown menu in Internet Explorer and Chrome

I am encountering an issue with my dropdown menu not functioning properly in Internet Explorer 10, Chrome, and compatibility mode. Surprisingly, it works flawlessly in the latest version of Firefox. CSS: #menu_items { float: left; width: 600px; } #me ...

Can variables be declared for file paths within the HTML code in a TypeScript file?

We utilize the Vaadin designer to create the frontend of our project. Within the .ts files, we have images where we aim to establish variables for the file paths. Currently, the setup looks like this: <img src="../../themes/light/img/example.jpg&q ...

Display or conceal specific fields depending on the selection from a dropdown menu

I'm currently experimenting with using JavaScript and/or jQuery to dynamically hide specific HTML elements based on the selection in a drop down menu. Here is what my page setup looks like: [Drop down menu] [text field 1] [text field 2] [text field ...

Transform a div's style when hovering over another div using absolute positioning without repetition

I am facing an issue with multiple divs positioned absolutely on top of a primary div with relative positioning. I want one specific div to change its background-color when hovering over another div within the same parent div. Though I know about ad ...

Clearing text fields in jQuery by cloning them

I am attempting to duplicate the friend fields (name + email) when the "add another friend" button is clicked. However, the cloned fields end up including the text inside them, which is not desired! Does anyone have any suggestions or solutions? Here is t ...

Show the cost on the HTML page according to the chosen currency option

I am currently dealing with two primary currencies in my business. The product page is created using HTML. There are 4 products on a single page, and I wish to display two prices for each product based on the selected currency (USD or EUR) without having t ...

I utilized Bootstrap to validate the form, however, despite the validation, the form is still able to be submitted. What steps can I take to

I have implemented form validation using Bootstrap's 'needs-validation'. However, I am facing an issue where the form still gets submitted even when the validation fails. What I want is for the form submission to be prevented if the validati ...

Displaying a random div using javascript

Seeking a way to display random divs on my webpage, I came across a stackoverflow solution: Showing random divs using Jquery The recommended code can be found here: http://jsfiddle.net/nick_craver/RJMhT/ Despite following the provided instructions, I am ...

What is the method for assigning a class name to a child element within a parent element?

<custom-img class="decrease-item" img-src="images/minus-green.svg" @click="event => callDecreaseItem(event, itemId)" /> Here we have the code snippet where an image component is being referenced. <template&g ...

Parent div is positioned absolutely with overflow set to hidden

I am facing a unique requirement where the parent div has an absolute position and the child div also has an absolute position. Inside the parent div, I have set overflow: hidden to hide the extra width of the child div. However, this setup is not working ...