Concerns with the height of CSS containers

I've encountered an issue where my container doesn't touch the footer in most cases, and I can't figure out what's causing it.

Let me share my CSS code:

html {
  min-height: 100%;
  position: relative;
}

body {
  margin: 0;
  width: 100%;
  height: 100%;
}

section {
  height: 100%;
}

#container {
  overflow: auto;
  width: 80%;
  margin: 0 auto;
  background: red;
  height: 100%;
}

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

And here's my HTML:

<body>
  <div id="container"> 
  <section>
  <p>Content goes here</p>
  </section>
  </div>
  <div class="footer">Content</div>
</body>

Even though I have set all heights for parent elements, there is still a noticeable gap between the container and the footer. When the content fills the entire page, the container and footer touch, but the content seems to get obscured by the footer. How can I address this problem?

Answer №1

Calculating height using percentages can be quite challenging. It is recommended to use vh for more accurate results.

To address this issue, you can check out the solution here: JSfiddle

#wrapper {
  overflow: hidden;
  width: 70%;
  margin: 0 auto;
  background: blue;
  height: 90vh;
}

Answer №2

Just make a small tweak to your CSS:

Simply include height: 100% in the html element.

html {
    height: 100%; /* UPDATED */
    min-height: 100%;
    position: relative;
}

By doing this, all child elements will be able to understand their percentage heights, resulting in the expansion of the container. Your min-height: 100% will still take effect since min-height supersedes height.

DEMO: http://jsfiddle.net/au6tcodc/

(In the demo, you might see a vertical scrollbar on the container. This is due to the overflow: auto declaration in #container. To remove the scrollbar, consider switching to overflow: hidden (view all available overflow values).

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

Leverage the power of the General Sibling Selector to easily traverse through deeply nested elements in your

Hi there, I have a query regarding the General Sibling Selector. Let's start by looking at the HTML: <div id="layout-middle"> <div id="Center"> <a class="col Picture1">Title1</a> <a class="col Picture2">Title2< ...

What is the best way to apply a CSS class to a ComponentRef that has been generated in Angular 5

I am attempting to dynamically add a CSS class to a component right after its creation by utilizing ViewContainerRef and ComponentFactoryResolver. My goal is to determine the class based on which other Components have already been added to myViewContainerR ...

Ensure that the browser is instructed to utilize a designated Accept field within the HTTP request

Can a web browser be directed to use a specific mime-type in an HTML request? For example, can we achieve this with the following code: <a type="application/pdf" href="https://url.com/">PDF</a> or <a type="text/html ...

Using jQuery and Ajax to populate a dropdown menu with options

I'm currently working on an ajax call function that successfully fills a drop-down list with data from a specific URL. However, I am looking to modify the function so that it can receive variables in order to populate the drop-down list dynamically. ...

Expandable full-width JavaScript accordion for seamless navigation

Currently, I am working on a simple on-page JavaScript application that consists of multiple data pages within one main page. My goal is to create a horizontal accordion effect where clicking on headers on either side will smoothly switch between the diffe ...

I need assistance with retrieving an image from a database using PHP

How can I display an image from the database on a new page using PHP? Whenever I click on the image, it always shows the same image on the new page. How can I make it so that the image displayed on the new page is the one I clicked on in the previous pag ...

The height percentage is not functioning properly even though it has been applied to the html, body, and all wrapper elements

I've been facing a persistent challenge with the height:100% problem. It seems like it should be an easy fix by ensuring all wrapper elements and html, body have height:100%, but no matter what I try, the containers still won't reach the bottom o ...

Failure to respond to dual part form by RemoveClass

Currently, I am utilizing jQuery to visually control a form. The issue arises when trying to remove classes from the first part of the form using removeClass. While this works initially, upon clicking the button to advance to the second part of the form, t ...

Customize the CSS style of a component in VueJS

After creating styles for my website, I encountered a challenge. Users input specific content using a WYSIWYG editor, and I want this content to have a distinct style without affecting the rest of the site. Despite trying various methods like , I couldn& ...

Gap created between two td or tr elements

Can someone please help me solve a troubling issue I'm facing with my CSS and HTML code? body { background-color:#ffffff; margin:0; padding-top:0px; } table.main-table-default { margin:0 auto; background-color:#00ffff; width:700px; border-collapse:co ...

Generating keyframes spontaneously, unable to remove commas

Initially, I acknowledge that this code may not be the most elegant. I have simplified it to show only the essentials. My objective is to dynamically create a @-webkit-keyframe based on input, generate a class, and then apply that class so an object can c ...

Using jQuery for slide shows in Ruby on Rails framework

I'm attempting to create a slideshow using jQuery and have the images stored in an array. However, I'm struggling with the implementation of the slideshow functionality. I've checked out 'http://jquery.malsup.com/cycle/' for guidan ...

CSS flexbox completely collapses all child elements that are empty

Is there a way to collapse the empty "col" divs in this html structure while keeping the content divs equally sized (two columns in this case)? * { box-sizing: border-box; } .container { border: 1px dashed rgba(255, 0, 0, .5); background-color: b ...

Instructions on creating a vertical height adjustment handle for a website

Is there a way to create a 100% height div that can be divided by a draggable border vertically? Take a look at my fiddle to see what I have so far: http://jsfiddle.net/k5rtbzs5/ This is the HTML code: <div class="column"> <div class="top"> ...

What is the best way to ensure my gif shows up in the top row and spans two columns in this grid?

I am attempting to create cards with a unique design where the first row consists of 2 columns, one being a GIF that shows the card fitting into a cell with a border. However, all I see is an empty cell without any display. Below is the code snippet I am ...

Text area featuring unique border design, with border color change upon focus?

Currently, I have a text area with borders that are designed in a unique way. However, I am looking to change the border color when the user focuses on the text area. Do you have any suggestions on how I can achieve this effect without affecting the curre ...

Troubles with CSS drop down alignment in Internet Explorer 7

I've been racking my brain all morning trying to solve this issue. My current project involves creating a website for a client, and I'm having trouble getting the dropdown menu to position correctly in IE7. It's working fine in all other br ...

Is there a way to dynamically alter the background style of a div by clicking on it multiple times using Javascript?

I am attempting to create a calendar where each day changes its background color between blue and green when clicked, using JavaScript and CSS. It should function similar to a toggle feature. The default color is blue, and I have successfully made the days ...

Activating the CSS :active selector for elements other than anchor tags

How can I activate the :active state for non-anchor elements using JavaScript (jQuery)? After reading through Section 5.11.3 of the W3C CSS2 specification in relation to the :hover pseudo selector in hopes of triggering the activation of an element, I stu ...

Eliminating data from selection options on a HTML menu list

Currently, I am facing an issue while attempting to incorporate a menu bar into my HTML page. After adding the icons, they are displaying with both underlines and dots at the back. I have tried using text-decoration=none; to remove the underline, but unf ...