Need assistance with CSS layout: How to extend a div to the bottom of the page

I am currently working on a design layout that includes a 'header' section with a logo and links, as well as a content area that should extend to the bottom of the page. However, I am facing some challenges in achieving this.

Initially, I enclosed the header and content within a container div set to a height of 100%, which worked well for the most part. But I struggled to make the content div stretch to the bottom of the container div without causing a scrollbar due to the space taken up by the header at the top of the page.

Below is a wireframe illustration to provide more clarity on what I am aiming to accomplish...

Additionally, here is a simple CSS code snippet that I have been experimenting with. While it functions correctly, there seems to be a persistent scrollbar that aligns with the height of the header region...

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    color: #fff;
}
body {
    background-color: #000;
}
#container {
    position: relative;
    margin: 0 auto;
    width: 1000px;
    min-height: 100%;
}
#header {
    padding-top: 26px;
}
#logo {
    width: 194px;
    height: 55px;
    margin: 0 auto;
    background-color: #fff;
}
#content {
    margin-top: 10px;
    position: absolute;
    width: 1000px;
    min-height: 100%;
    background-color: #fff;
}

Answer №1

http://jsfiddle.net/CZayc/

this solution involves enclosing the header and body within a div element to ensure proper footer placement

index.html

<div id="wrap">
    <div id="header">
        Header Content
    </div>
    <div id="main">
        Main Content<br/>Main Content<br/>Main Content<br/>Main Content<br/>Main Content<br/>Main Content<br/>
    </div>
</div>
<div id="footer">
    Footer Content
</div>

style.css

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { 
    margin:0;
    padding:0;
}
#header {
    border-top:20px solid #fff;
    height: 33px;
    line-height: 33px;
    text-align: center;
    background-color: green;
}
html { height: 100%; }
body { height: 100%; width: 90%; margin: auto; }
#wrap { min-height: 100%;background-color:gray;}
#main {
    overflow: auto;
    padding-bottom: 53px; /* must be same height as the footer */
    background-color: red;
    height: 90%
}
#footer {
    position: relative;
    margin-top: -53px; /* negative value of footer height */
    height: 33px;
    line-height: 33px;
    border-bottom:20px solid #fff;
    text-align: center;
    background-color:blue;
}

Answer №2

To create the desired layout, set the container div to have a position of relative and the content div with a position of absolute. Next, assign the top attribute of the content div to be the height of the header and set the bottom attribute to 0.

Although I am unable to verify this at the moment, implementing these changes should achieve the desired result.

Answer №3

constraints: header must have a fixed height that doesn't change.

content height can vary.

CSS code:

* {
    padding:0;
    margin:0;
}
html, body {
    height: 100%;
    color: #fff;
}
#header {
    background: red;
    position: absolute;
    z-index:20;
    height: 7em;
    overflow:hidden;
    width:100%;
}
#content {
    background: blue;
    position: absolute;
    top: 0;
    padding-top: 7em;
    min-height: 100%;
    box-sizing: border-box;
}

content should extend to the bottom of the page, even with short text.

if content's text exceeds window height, auto scroll will be activated.

Check out an example here: http://jsfiddle.net/fixit/p3B4s/3/

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

Floating elements are misaligned and not laying out correctly

I've encountered an issue where the footer div is appearing behind the right-hand side div. I have a central container div with two floated divs next to each other, and the footer is separate. I've spent hours trying to fix it but can't figu ...

Header with absolute positioning doesn't play nice when nudged in Chrome

Take a look at the HTML page on this JSFiddle link: http://jsfiddle.net/rb8rs70w/2/ The page features a "sticky" header created using CSS with the property position: absolute. ... <body class="body-menu-push"> <header role="banner"> ...

Using React js to create a blurred background effect when an input field is in focus

I would like to implement an input field similar to the one shown in the image. When the input field is clicked on, I want to blur the background. image example Do I need to use a specific library for this? Currently, I am using Material UI. ...

What is the best way to center text within a button when there is also an image present?

I'm trying to create a button with an image and some text, but I can't seem to get it aligned properly. Here's the code I have so far: <button><img src="https://www.google.com/s2/favicons?domain=google.com">&nbsp;Go ...

"Customizing the color of the arrow in Bootstrap tooltips

Trying to customize tooltips in twitter-bootstrap, I set the template option of the tooltip with inline styles to achieve red tooltips instead of the default black color: $(document).ready(function(){ options = { container: 'body&ap ...

Creating smooth and natural movement of a div element using Javascript (rotating and moving)

After struggling to use jquery plugins for smooth motion with the div elements I'm working on, I've decided it's time to seek some assistance. I have a group of div elements that all share a class and I want them to move around the screen c ...

Remove the color gradient for the column headers in the Google Visualization table

Whenever I attempt to change the colors of the column headers using the method demonstrated in this insightful source, a rather generic gradient is applied. Interestingly, the example code provided also demonstrates the same default gradient on the secon ...

Navigating between two intervals in JavaScript requires following a few simple steps

I have created a digital clock with a button that switches the format between AM/PM system and 24-hour system. However, I am facing an issue where both formats are running simultaneously, causing the clocks to change every second. Despite trying various s ...

The page fails to load when redirected, however, it briefly displays the page upon clicking the back button before navigating back to the previous page

Currently, I am working with Angular 2 and encountering an issue when attempting to click on a link. The loading bar continues to progress without displaying the data or HTML content on the page. Furthermore, if I try to go back to the previous page, the i ...

Creating a ToggleButton in C#Is a Togglebutton the

I am trying to create a togglebutton for a website with Microsoft Visual Studio and am not sure if this would be the correct code to apply. I am working in C#, so the button is going to be generated in C# (and a bit of jquery) code and eventually styled in ...

Make sure that the iframe loads the next page with enough force to break out

My dilemma involves an iframe that loads the new tab page. When a user clicks on the thumbnail, it opens within the iframe. My goal is to have any subsequent load in the iframe redirected to window.top. Is there a way to achieve this without manually setti ...

CSS3 columns causing <li>s to be cropped

I'm attempting to implement css3 columns with a list (<li>), but I'm running into some issues getting it to function properly. I have wrapped the <ul> in a div like this: .ul-container { -moz-column-width: 310px; -moz-column-gap ...

Having trouble integrating the css and js animation files into my Django project

settings.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '@6qt%i+0&_=z0#zl^+!u3bw6c7dmg4e3khboj%7s7439z9#ky(' DEBUG = True ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'django.contrib.admin& ...

Is it possible to showcase a notification as a popup or alert in Django?

I'm working on a form in Django that redirects to itself after submission. I want to show a message saying "You have entered (work_area)" as a popup or alert that users can close. However, my current setup only displays the message within the HTML aft ...

I am having difficulty accessing specific data in JSON using Searchkit's RefinementListFilter

Utilizing searchkit for a website, I am encountering issues accessing previously converted data in json format. The structure of my json directory is as follows: (...) hits: 0: _index: content _type: content _source: ...

Having issues with the CSS dropdown menu not activating when hovering

I am facing an issue with a simple menu that includes a dropdown feature upon hovering. The code works perfectly fine in Fiddle, however, it fails to work when running the entire page locally on IE. Can someone please assist me? (here's my code at fi ...

React createElement function does not include string children when there are multiple children present within the inner HTML

Currently, I am utilizing React.createElement(...) to dynamically produce a basic react website using data from a JSON file. The JSON file consists of an array of JSON objects that represent elements and their respective children. An individual element&ap ...

What steps should I take to make the code in jsfiddle functional on my Visual Studio Code platform?

const canvasEle = document.getElementById('drawing-container'); const canvasPad = document.getElementById('pad'); const toolbar = document.getElementById('toolbar'); const context = canvasEle.getContext('2d'); const ...

Building a local database using the MVC framework concept

Can a locally stored database be developed using MVC framework principles in javascript and html5? Thank you Ravindran ...

The proper way to link a style sheet within an MVC framework

Currently, I am working on transitioning a website that I created in the Atom text editor to an ASP.NET environment. To adhere to best practices, I have decided to implement the MODEL VIEW CONTROLLER design pattern in this project. While attempting to ad ...