Ensure that the footer is always positioned at the bottom of the page according

I've been struggling to get my footer to stay at the bottom of the page based on content. I've tried several CSS techniques and strategies, but I'm still encountering one issue.

footer {
    width: 100%;
    padding: 25px 0 25px;
    background: #1e1e1c;
    position: absolute;
    bottom: 0;
}
body, html {
    font-family: 'sairaregular';
    font-size: 100%;
    margin:0;
    padding:0;
    height:100%;
}

When I apply this CSS for some content pages, it looks like they are located at the bottom. You can see an example here: https://i.sstatic.net/ShJ7B.png.

However, it's not truly at the end of the page; it just appears at the bottom when the page opens. Can anyone suggest a solution to fix this issue? Thank you in advance.

Answer №1

Give this a try:

body{
  margin:0;
}

#page-container {
  position: relative;
  min-height: 100vh;
  background-color: grey;
}

#footer {
  color: white;
  background-color: black;
  position: absolute;
  bottom: 0;
  height: 40px;
  width: 100%;
}

#content-wrap {
  padding-bottom: 40px;
}
 <div id="page-container">
    <header>
      Content for the header
    </header>
    <div id="content-wrap">
      Main content area
      <footer id="footer">
        Footer content goes here
      </footer>
    </div>
  </div>

Answer №2

To achieve the desired layout, you can utilize the flex property for the parent div and specify a height property.

Here is the HTML markup -

<body>
  <div id="page-container">
    <div id="content-wrap">

    </div>
    <footer id="footer">

    </footer>
  </div>
</body>

And these are the necessary CSS properties -

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

#page-container{
  display:flex;
  flex-direction: column;
  height: 100vh;

}

#footer{
  padding: 20px;
  background: #DDD;
  margin-top:auto;
}

You can view an example of this implementation in action by visiting this link.

In the html section provided, try uncommenting the p tags to observe how the layout behaves when the content exceeds the visible page boundaries.

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

What can I do to prevent my background images from overlapping each other?

I'm trying to get the background images to display side by side with equal sizes and no spacing between them. The current code achieves this, but the images end up overlapping slightly, not filling 100% of the container. Despite setting the backgroun ...

Does the flex-grow property depend on the flex-basis in flexbox?

Check out this snippet of HTML code <div class="container"> <div class="box box1">one ...

CSS- The ultimate guide to perfectly centering a webpage without the need for extra margins!

Our SharePoint 2013 generated web page has a width of 1024. The main content div is styled as follows: #container_master { width:1024px !important; margin-left: auto !important; margin-right: auto !important; background-color:#FFF !impor ...

I am having trouble with the vertical alignment in the middle

I'm having trouble getting the text in front of the image to be centered within it! Despite trying to use vertical-align middle, it doesn't seem to be working... What could be causing this issue? <div class="comments"> <div class="pul ...

Encountered a problem while constructing Angular application with agm-spiderfier

Encountering an error during code compilation with AGM Spidefier library. The file \node_modules\agm-spiderfier\index.ts seems to be missing from TypeScript compilation. Ensure it is included in your tsconfig file under the 'files' ...

Set the style of the mat-select element

I'm having an issue with my select option in Angular Material. The options look fine, but when I select one, the strong tag disappears. Can anyone help me style only that part? Thank you in advance. <mat-select formControlName="projectId" ...

Adding a background color to the body of your PHP and HTML email template is a simple way to enhance

I am currently using a confirmation email template with a white background, but I want to change it to gray. However, I'm unsure how to update the PHP file containing the email function below: $headers = "From: " . stripslashes_deep( html_entity_deco ...

Bringing in Angular Material on Stackblitz

After importing material(7.2.1) into my stackblitz link, I am still unable to see the exact UI of material. I have tried to figure it out, but no luck. You can view the stackblitz I created here. ...

CSS Background Image Properties

I'm struggling to display a background image on my HTML page. The image is saved in the same folder as the HTML file. <html> <head> <link rel="stylesheet" type="text/css" href="style/indexstyle.css" > <meta charset="ISO-8859-1"& ...

Displaying and hiding the top menu when the div is scrolled

I have developed a script that is designed to display the menu in a shaking motion and hide it as you scroll down. It functions properly when scrolling within the body of the webpage, but I am facing issues when attempting to do so with a div that has an o ...

An Iframe lacks the ability to showcase HTML content, unlike a browser which is capable of doing

I'm struggling to get my Iframe to show the html string properly. Here's the content of the string: var='<BODY style="MARGIN: 0px" bgColor=#ffffff marginwidth="0" marginheight="0"> <SCRIPT language=JavaScript> var Caller_User_Ty ...

Updating Button Text Upon Click

I am looking to create a webpage filled with riddles. After each riddle, there will be an answer button that, when clicked, reveals the answer. Clicking the button again should hide the answer. I attempted to implement this functionality using Javascript, ...

Make the bootstrap row stretch beyond the confines of the container

Our website is currently using Bootstrap 3, and one of our team members has proposed a new template design that deviates from the typical Bootstrap grid layout. I've attempted to implement this design but have faced some challenges along the way. I h ...

The function of modal in JavaScript is not working properly

I am encountering a problem with my web page that is running on Wildfly 12. It is a simple Java EE project that I developed in Eclipse Neon. The issue arises when I try to use Bootstrap modals, as every time I attempt to open or use the methods in a JavaSc ...

Using Firebase Data in Angular5 Component with MathJax Integration

I am facing an issue where I need to update the data retrieved from Firebase in a way that equations are displayed on the page instead of random symbols representing Latex syntax. While I have successfully integrated MathJax into my project through a scrip ...

What is the reason behind Bootstrap 5 inserting a line break following a span element?

Other questions similar to this one have been raised, but they do not cover a straightforward example of the problem. When looking at the code snippet below, you will notice that a line break is inserted after the closing span tag if Bootstrap 5 is utilize ...

Step-by-step guide on accessing values from a JavaScript object

I have a dictionary variable declared within a script tag on an HTML page. My goal is to retrieve the values associated with the "Roads" and "Intersections" keys, which change each time the page is refreshed. By capturing these values, I can then use JavaS ...

Displaying image issues persist on Safari browsers for Mac and iPhone

I am currently working on a website and facing an issue with the responsive image display on Safari for Mac/iPhone. Here is the code snippet I have been using: <head> <meta charset="utf-8"> <meta http-equiv="Content-Language" co ...

Showcasing a Collection of Dropdown Options for All Angular Material Icons in Angular Versions 2 and Above

I'm currently developing an Angular 10 application that utilizes Angular Material Icons. I am in search of a method to dynamically showcase a dropdown menu containing all the available Material Icons. My attempt to programmatically retrieve the icon ...

Enhancing image clips using jQuery techniques

Could someone help me figure out why the image clip value isn't changing when I move the range slider in the code below? $('#myRange').on('input', function() { var nn = $(this).val(); $("img").css({ 'clip': ...