What could be causing the footer to not show up at the bottom of the page?

I've encountered an issue with my code where the footer appears to be stuck at the bottom of the h2_c div instead of the bottom of the .content div where it should be. I have tried using positioning but it hasn't resolved the problem.

Thank You.

.header {
  background: #a7a7a7;
  min-height: 700px;
  position: relative;
}
.content {
  width: 940px;
  margin: 70px auto 0 auto;
}
.h2_c {
  color: #333;
  font-weight: bold;
  font-size: 20px;
  text-align: center;
  margin-bottom: 30px;
}
.one {
  float: left;
  width: 300px;
  height: 400px;
  background: green;
  position: relative;
}
.info {
  position: absolute;
  bottom: 0;
  width: 100%;
}
.two {
  float: left;
  width: 300px;
  height: 400px;
  background: green;
  margin-left: 20px;
  position: relative;
}
.three {
  float: right;
  width: 300px;
  height: 400px;
  background: green;
  position: relative;
}
.h2 {
  color: #fff;
  font-size: 28px;
  padding: 20px 20px 10px 20px;
  margin: 0;
}
.p {
  color: #ccc;
  margin: 0;
  padding: 0px 20px 10px 20px;
  font-size: 16px;
}
.span {
  color: #fff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 3px 10px 3px 10px;
  font-size: 11px;
  -webkit-border-radius: 28px;
  -moz-border-radius: 28px;
  border-radius: 28px;
  background: blue;
  margin: 20px;
}
.footer {
  border-top: 4px solid orange;
}
<div class="header"></div>
<div class="content">
  <h2 class="h2_c">Content</h2>
  <div class="one">
    <div class="info">
      <span class="span">Text 1</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
  <div class="two">
    <div class="info">
      <span class="span">Text 2</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
  <div class="three">
    <div class="info">
      <span class="span">Text 3</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
</div>
<div class="footer"></div>

Answer №1

Your "really cool text" sections that are floated are overflowing outside of the .content section because floats do not affect the height of their container by default.

To fix this issue, add overflow: auto to the .content class to establish a new block formatting context as described in CSS specifications.

.header {
  background: #a7a7a7;
  min-height: 700px;
  position: relative;
}
.content {
  width: 940px;
  margin: 70px auto 0 auto;
  overflow: auto;
}
.h2_c {
  color: #333;
  font-weight: bold;
  font-size: 20px;
  text-align: center;
  margin-bottom: 30px;
}
.one {
  float: left;
  width: 300px;
  height: 400px;
  background: green;
  position: relative;
}
.info {
  position: absolute;
  bottom: 0;
  width: 100%;
}
.two {
  float: left;
  width: 300px;
  height: 400px;
  background: green;
  margin-left: 20px;
  position: relative;
}
.three {
  float: right;
  width: 300px;
  height: 400px;
  background: green;
  position: relative;
}
.h2 {
  color: #fff;
  font-size: 28px;
  padding: 20px 20px 10px 20px;
  margin: 0;
}
.p {
  color: #ccc;
  margin: 0;
  padding: 0px 20px 10px 20px;
  font-size: 16px;
}
.span {
  color: #fff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 3px 10px 3px 10px;
  font-size: 11px;
  -webkit-border-radius: 28px;
  -moz-border-radius: 28px;
  border-radius: 28px;
  background: blue;
  margin: 20px;
}
.footer {
  border-top: 4px solid orange;
}
<div class="header"></div>
<div class="content">
  <h2 class="h2_c">Content</h2>
  <div class="one">
    <div class="info">
      <span class="span">Text 1</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
  <div class="two">
    <div class="info">
      <span class="span">Text 2</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
  <div class="three">
    <div class="info">
      <span class="span">Text 3</span>
      <h2 class="h2">Some really cool text</h2>
      <p class="p">Text text text text text text text text text text text text text text text text text text.</p>
    </div>
  </div>
</div>
<div class="footer"></div>

Answer №2

When you use the float property on an element, it removes that element from the normal flow of HTML. To fix issues with floating elements, you can add a line like this:

<div style="clear:both"></div>

By placing this right after your three floating div's, it will help keep things in order.

Another option is to use the CSS pseudoelement :after with the property clear: both, but I prefer the first method for better compatibility across older browsers.

Sometimes adding overflow:hidden can also solve the problem, but I personally don't like this approach as it may hide overflow content unintentionally.

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 is the best way to create a clickable button link using PHP echo?

Whenever I click the button, it always redirects to just story.php, ignoring all other details. I attempted using JavaScript but I found that utilizing form action is the closest method for me to accomplish this: <form action='./story.php?u=$id&a ...

Arranging XML information in PHP from most recent to oldest

I have a working code that I want to modify so that the Observed Data is displayed from the newest date to the oldest. How can I flip only the Observed Data? Here is my current code: <?php $url = "http://r7j8v4x4.map2.ssl.hwcdn.net/NOD_R.xml"; $xml = ...

Is there a way to display data in a checkbox field using PHP and JQuery Mobile?

I am currently working on a challenge in viewsessions.php. My goal is to retrieve multiple values from a database and group them into checkbox fields (such as typeofactivity, employer, date, time, amount as one combined checkbox field) using <input type ...

What could be causing the issue with the focus not being activated when clicking on the input field in Vue?

I am facing an issue where I have to click twice in order to focus on a specific input field, and I'm having trouble setting the cursor at the end of the input. I attempted to use $refs, but it seems like there may be a deeper underlying problem. Any ...

What causes absolute positioning to separate each word onto its own line? Is there a solution to this issue?

Why does each word in a child element (class .second) get wrapped onto a new line when using absolute positioning? Is there a way to keep the parent element (class .first) as a round shape, while also ensuring the child element is centered below it and has ...

React component utilizes Material UI to detect scrolling within a table

Currently, my table's body size is set to fixed dimensions in accordance with Material UI guidelines. I am looking to implement a functionality that allows me to dynamically load more rows as the user scrolls through the table. Can you recommend the ...

Add an arrow or triangle at the tip of the line

I am currently working on recreating the design of lines with an arrow or triangle at the end side of an Input form. The inspiration for this comes from an old flash application that is now being converted to HTML5: So far, I have managed to create the li ...

Error in line 36: firebase.auth function is undefined

Snippet of index.html code <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" ...

Ways to show buttons as inline or block elements when a single button is enclosed within a form

Need help figuring out how to make two buttons display as block elements on small screens and inline elements on larger screens, especially when one button is wrapped inside a form? I am struggling with displaying two buttons on my page. One of the button ...

The canvas is responsive to keyboard commands, however, the image remains stationary and unaffected

As I delved into the basics, incorporating canvas, CSS, and JavaScript, a question arose: should the image be housed in the HTML or the JavaScript code? Following this, I added a background color to the canvas and defined properties of the canvas in JavaSc ...

Is it possible to retrieve information from a json file?

I am looking to extract specific elements from a JSON response fetched using the YouTube API. Here is an example of the response I receive in my script: { "version": "1.0", "encoding": "UTF-8", "feed": { // Details of the feed... } } My goal ...

What is the best way to create a dynamic textbox or label within a specific div class?

I need assistance with my dynamic asp.net page where I am generating labels and text boxes in a form. Is there a way to ensure that these elements are generated within a specific div class? Below are the relevant code snippets: for (int i = 0; i < cou ...

The gap between columns in Bootstrap grids

Currently, I am dynamically fetching "boxes" and adding them to the HTML document using ngFor. The number of boxes is unknown in advance. Here is the code I am currently using: <div *ngIf="items && items.length" class="row"&g ...

Are there any reliable sources for a complete list of browser CSS properties?

Is there a way to easily access a comprehensive list of CSS properties supported by specific browsers, particularly IE8? Any suggestions on where I can find this information? ...

HTML - maintain centered text positioning while implementing padding on the left side

Here are the HTML and CSS code snippets I am working with: #page { background-color: #000; color: #fff; height: 360px; width: 360px; min-height: 100%; } #viewport { font-size: 20pt; text-align: center; } .taskTitle { height: 13%; fon ...

Assignment of Microsoft Avatar Colors

What method does Microsoft utilize to assign colors to contacts in their applications? I've searched online with no luck in finding an answer. In programs like Outlook or Android, when a new contact is added without an image for the avatar, Microsof ...

When the add button is clicked, I would like to implement a feature where a checkbox is added

When the user clicks on the link "출력하기", I want the web page to add a checkbox to all images. I wrote this code, but it's not working. Can anyone help me? This is my JS: $(document).ready(function(){ $("#print").on('click', fu ...

The separator falls short of spanning the entire width of the page

For some reason, I can't seem to make the divider extend to the full length of the page. <TableRow> <TableCell className={classes.tableCell} colSpan={6}> <Box display="grid" gridTemplateColumn ...

Guide on setting up p-menubar in PrimeNG to expand in the opposite direction, from left to right, for the responsive

How can I modify the CSS styles or configure the p-menubar from PrimeNg to have it expand from right to left in the responsive version? Currently, when using the classes align-items-center flex justify-content-between, the menu remains stuck to the right e ...

What is the best way to choose every single element on the webpage excluding a specific element along with all of its children?

Is there a way to hide all content on a page except for a specific element and its children using CSS? I've been exploring the :not selector, but I'm struggling to make it work with the * selector. :not(.list-app) { display: none; } :not(. ...