Create CSS styles for various sections with a minimum height of 100% and include a sticky footer for

Many people have asked about creating a sticky footer and main containers with 100% min-height. But how can I achieve this for multiple sections, ensuring each one has a 100% min-height while still pushing the footer below?

Currently, my sections are set to 100%, but the footer remains at the top.

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>test</title>
    <style type="text/css" media="all">
      html, body, .main-container{height:100%;}
      section{min-height: 100%;}
      .footer-container{height: 100px;}
    </style>
  </head>
  <body>
    <div class="header-container">
      <header>
        header
      </header>
    </div>
    <div class="main-container">
      <section>
        section
      </section>
      <section>
        section2
      </section>
      <section>
        section3
      </section>
    </div>
    <div class="footer-container">
      <footer>
        footer
      </footer>
    </div>
  </body>
</html>

Check out the corresponding jsFiddle here: http://jsfiddle.net/S7h8s/

Answer №1

Impressive sticky footer using Compass at its finest! Explore here for more details

Answer №2

After making some adjustments, I managed to get it to work by changing the layout:

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>test</title>
    <style type="text/css" media="all">
      html, body {height:100%;}
      section{min-height: 100%;}
      .footer-container{height: 100px;}
    </style>
  </head>
  <body>
      <header>
        header
      </header>
      <section>
        section
      </section>
      <section>
        section2
      </section>
      <section>
        section3
      </section>
      <footer>
        footer
      </footer>
  </body>
</html>

You can view the updated jsFiddle here:

http://jsfiddle.net/S7h8s

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 - Delayed Text Appearance with Smooth Start

I want to create a landing page where the text appears with a slight delay - first, the first line should be displayed followed by the second line. Both lines should have an easing effect as they appear. Below is a screenshot of the section: https://i.sst ...

use angularjs directive to position a div absolutely aligned with the right edge of another div

I am attempting to use an angularjs directive to align the right side of an absolute div with another div. The code is working, but I am encountering an issue where the children divs are slightly wider than their parent, causing the offsetWidth value to be ...

Use jQuery to apply CSS to a div only when it becomes visible on the screen

I created a single page HTML with scrolling functionality. The structure of my divs - home and home2 - is as shown below. Both have a height of 100%. I am looking to add CSS to the second div (home2) using jQuery only when it becomes visible to the user in ...

Tips for directing attention to a div element

Need some help here! I'm just starting out with JS and jQuery, so please be gentle. Is it possible to set focus on a div element? I am looking to trigger events when the div is clicked or focused, as well as when clicking outside of the div. Here&apos ...

Using JavaScript to alter CSS styles with dashes

Currently, I'm delving into the world of manipulating CSS using JavaScript: img.style.borderRadius = "100%"; img.style.border = "9px solid #ffffff"; img.style.boxShadow = "0 0 5px #00000070"; img.style.margin = "20px"; I'm wondering how to chan ...

The PHP SDK function works flawlessly in the local host environment and in console, however, it fails to perform on the browser when deployed

My PHP function is behaving differently between the server's command line and the web page, with successful execution on a local WAMP host. Any thoughts on what could be causing this inconsistency? function getCFTemplateSummary($CFUrl){ //init client ...

Tips for delivering a variable to a React Native Stylesheet

Is there a way to pass a variable to the "shadowColor" property in my stylesheet from an array declared in the code above? I keep encountering a "Can't find name" error. Attempting to use a template literal has not resolved the issue. Any assistance w ...

What could be the reason for my new course not being recognized?

Looking to modify the behavior of a button where, when clicked, it hides a specific div element, changes its text display, and toggles between classes using addClass/removeClass for subsequent click events. Unfortunately, the intended functionality is not ...

Ensuring a smooth user experience on Internet Explorer with CSS backup

I am looking to incorporate a CSS 3D effect into a website. I have successfully implemented it on all browsers except Internet Explorer (including IE 11). As far as I know, IE does not support preserve-3d. Can someone help me add a fallback option for IE, ...

Adjust the background color of the choices in the select box

I'm looking to customize the appearance of a drop-down menu in a form on a website by making the background of the options transparent, similar to the initial selection. I've tried using background:rgba(255, 255, 255, 0.2) for this purpose, but ...

Modify the background of a div according to the size of the screen. Implement this functionality using JavaScript and

After reviewing a specific post at , I find myself unsure of how to target a particular class for reference. I am certain that I want to implement document.onload = checkWidth(); window.onresize = checkWidth(); However, I am uncertain about the procedur ...

The list-image is nowhere to be found

Seeking assistance with my LI style CSS. Visit this link for reference I'm having trouble getting an image to float on the right side of my sidebar links, and my content is overlapping with the sidebar... .sidebar-menu ul { font : 14px font-fam ...

What are the reasons to steer clear of setting y.innerHTML equal to x.innerHTML?

If we have a DIV x on the webpage and want to duplicate its contents into another DIV y, we might be tempted to use the following code: y.innerHTML = x.innerHTML; This can also be achieved using jQuery: $(y).html( $(x).html() ); However, it is recommen ...

ReactJS does not trigger a re-render when changes are made to CSS

I'm curious about the reason why ReactJS does not automatically reapply CSS to child components even when componentDidUpdate() is called. I conducted a small demo where adding a new box doesn't change the color of existing boxes, even though the ...

Utilize jQuery to serialize the HTML input elements that are dynamically generated outside of the form

A proof of concept is in progress for an application that involves the generation of HTML elements based on user-configured fields. Here is a sample configuration: // Customer SAM $response = array( array ( NAME => CUSTOMER, TYPE = ...

What is the best way to display an income statement div with three elements in a vertical position once the screen reaches a medium width?

Can anyone help me create an income statement div with three elements that has a responsive layout? I want these elements to change from a horizontal display to a vertical one when there is limited space, especially on medium width screens. The initial la ...

conceal only a few HTML elements

When a user enters text into my comment box, it is saved in the database with additional formatting. For example: aa @Martins <aabb> The saved version in the database looks like this: aa <span class="highlight" contenteditable="false">@Marti ...

What is the process for linking an HTML document to another HTML document within a div using jQuery?

Check out my HTML code: <!DOCTYPE html> <html> <head> <title>Hilarious Jokes!</title> <meta charset="utf-8"> <link href="final%20project.css" rel="stylesheet"> <script src=" ...

What is needed to enable the functionality of the next and previous buttons? (Carousel Bootstrap)

I'm working on a text-only carousel using Bootstrap, but I'm facing an issue with the slider not functioning properly when I press the "next" and "prev" buttons. Any assistance would be greatly appreciated! <link rel="stylesheet" href="htt ...

A plethora of color choices in a Multi-select Box

Hi there! I am facing an issue with dynamically adding multiple select boxes. Currently, I have 4 color-coded options under the selection boxes, which work fine when there is only one box. However, when I add more than one select box, the color coding doe ...