Tips for placing the footer at the bottom of the page and ensuring it is pushed below the content as the amount of content increases

I am struggling to position the footer on my webpage at the bottom of the screen when there is limited content. If the content height exceeds the screen height, I want the footer to flow below the content instead of staying fixed at the bottom.

Despite trying several suggestions from stackoverflow and other sources, I have not been successful in achieving this.

I am currently attempting to implement the solution provided at the following link, but I am having trouble adapting it to my HTML structure:

https://codepen.io/cbracco/pen/zekgx

HTML

<div class="site-wrapper">
    <header>
        Header
    </header>
    <div class="home-body-wrapper">
        Body
    </div>
    <footer>
        Footer
    </footer>
</div>

Using Bootstrap + Custom CSS

html {
  height: 100%;
  box-sizing: border-box;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}
body {
  height: 100%;
  background-color: #ffffff;
  color: #ffffff;
}
.site-wrapper {
   height: 100%;
   position: relative;
   background-color: #6cacc5;
   padding: 50px;
}
.site-wrapper header {
  height: 50px;
  background-color: #3b5998;
}
.site-wrapper .home-body-wrapper {
  min-height: 300px;
  background-color: #c97874;
}
.site-wrapper footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 200px;
  background-color: #555555;
}

jsfiddle

Answer №1

To enhance the responsiveness of your layout, consider swapping out height: 100% in the style for .site-wrapper with min-height: 100vh. This adjustment allows the content to expand beyond the viewport if needed, unlike using height which restricts it entirely.

Answer №2

My approach involved eliminating the site-wrapper, setting the body position as relative, applying a min-height: 200px to the body, and introducing top and bottom padding to the content wrapper. I mostly kept the remaining code similar to yours.

html {
  height: 100%;
  box-sizing: border-box;
  margin: 0;
}

body {
  min-height: 100%;
  margin: 0;
  color: #ffffff;
  background-color: #6cacc5;
  padding: 50px;
  position: relative;
}

header {
  height: 50px;
  background-color: #3b5998;
}

.home-body-wrapper {
  min-height: 300px;
  background-color: #c97874;
  padding: 50px 0 200px 0; 
}

footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 200px;
  background-color: #555555;
}
<body>  
<header>
    Header
  </header>
  <div class="home-body-wrapper">

    <p>Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies
      mi eu turpis hendrerit fringilla.</p>

    ... (remaining content stays the same)
    
  </div>
  <footer>
    Footer
  </footer>
</body>

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

JavaScript Event Listener causing the Sticky Position to Break

I am currently dealing with a situation where I want to create a slide-in side menu that remains sticky. However, when I apply the position: sticky CSS property to my menu container, it causes the entire menu to be displayed (instead of being pushed off th ...

Is there a way to continuously cycle through multiple images fading in and out at various locations on a webpage using absolute positioning?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Harley's Art Gallery</title> <script t ...

What steps do I need to take in order to obtain the value for insertion into a form for editing, so that the record

In order to display all book records in a table and provide the functionality to edit these records, you can utilize the following code snippet. This code includes a button that redirects to the editbook.html page where you can update the record: <tbody ...

I struggle to build a CSS dropdown menu from scratch

I attempted to create a dropdown menu, but it seems to be malfunctioning. Can anyone identify the error? .dropdown1{ width: 200px; height: 110px; background-color: white; border: 5px solid black; position:absolute; left: 400px; ...

Tips for crafting interactive Dropdown menus

Visit this link for more information Hello all, I am a beginner in HTML and Javascript and seeking guidance on how to create dynamic dropdown menus similar to the ones on the provided website. I have successfully implemented the source code, but my questi ...

jQuery Hierarchical Select Menu

I am working on creating a complex hierarchy of dropdown options. The goal is to display only the options that are related to the previously selected choice. For example, if "Device Groups" is selected, the second dropdown will default to "Group Details" a ...

The functionality of Table 3 column is not compatible with Internet Explorer 8

In IE8, strict mode (as I am unable to use normal mode), the 3-column layout is not displaying correctly. The following link shows a two-column layout where the second div occupies the remaining space: http://jsfiddle.net/JWBgY/ However, in the three-col ...

Guide on building a dynamic grid layout with dual sides?

https://i.sstatic.net/P95ad.png My current code is causing some issues and not displaying as desired. I have included a sample of my code below: <style> .red{ background-color: red; } </style> {% endblock stylesheets %} {% block co ...

stop bootstrap collapse from re-activating when an item is clicked

I'm currently facing an issue with my sidebar that is implemented using bootstrap collapsible. The menus are all in tags, but the problem arises when I click on one of these tags - the page refreshes, re-animating the collapsible panel and creating a ...

Experiencing an unusual gap following the menu on mobile view for my WordPress website?

I recently launched a WordPress website dedicated to education. In order to make some adjustments, I added subheaders to each page with a simple display:none setting. Surprisingly, while everything looked perfect on desktop view, I noticed some extra spa ...

Learn how to create an animated refreshing icon in React when clicked

I have a refresh icon in my React app that utilizes Material UI. I want the icon to spin for a second after it is clicked, but I am unsure of how to achieve this. Despite attempting some solutions, none have been successful. const useStyles = makeStyles(( ...

Using PHP and an HTML form to input multiple data entries into a MySQL database

I am currently working on a project that involves reading and inserting columns and rows from an HTML form into a MySQL database using PHP. When trying to execute the code, I encountered the following error: Undefined index: maintenance on line 28 Undef ...

Determine the combined width of each child element and divide it by two

I am working on a div that has multiple children inside. To achieve a horizontal layout, I need to set a width on the parent div so that the content flows from left to right. Instead of having all items in one row, I want them to be split into two rows. Th ...

Raising css properties using jquery

Is there a way to adjust CSS values using jQuery? I am looking to specifically increase values like top and left, but my current attempt is not producing the desired outcome: var left = 5; $(.object).css("left" + 5); The challenge I am facing is that I ...

Responsive design may not always function properly on iPhones

Initially, this is how Chrome Dev Tools displayed it to me; https://i.sstatic.net/9ZyHb.png It appeared normal and responsive, but when I shared it with my friends, they showed me this instead; https://i.sstatic.net/W0Hk9m.jpg It looks completely diffe ...

I wish to input a continuous flow of information from a JavaScript file into an HTML text box

Being an absolute beginner in the coding world, I recently attempted to create an app for a Tizen device (Samsung Gear S) that could read and display heart rate data. Initially, I utilized templates and tried writing data to the filesystem but faced some c ...

Displaying random divs and subsequently animating them downwards using JavaScript

I am in the process of creating a random appearing div that then falls down. Here is the code I have so far: $(document).ready(function(){ $('#test').animate({top: 80 + '%'},900); }); <div id="test" style="background:#98bf21;heigh ...

Adjusting Text Color on Buttons

I am looking for a simple button with clear color and black text, but the default button has white text. I need a way to change the text color. Check out my current app <View style={styles.fastlog}> <Button style={styles.bouton} title= "Con ...

Executing a function on a dynamically generated JavaScript button

Is there a way to create a button that triggers an onClick event calling a function with the signature deleteEntry(entry)? I'm encountering an error stating that entry is undefined even though I have used it in the same function. Adding escape charact ...

The selection of an HTML option should dynamically generate additional select options based on the chosen value

My goal is to develop a dynamic select option feature where the selection of a value in the dropdown menu would populate additional select options. For example, if the user selects '3', it should generate 3 more select options. This functionality ...