designing a CSS layout with content that fills the height

I'm facing a challenge with CSS as I work on adapting a website. I need to create a layout that includes a container_div beneath the body element, both set to 100% height. The header should be 170px tall, followed by a content div that stretches from the bottom of the header to the top of the footer. The footer itself should have a fixed height of 50px.

Within the content div, there will be left and right divs positioned relative with floating properties applied. I want a design similar to an example found at this link, but with overflow hidden for the content area using a custom scrollbar script.

The part I'm struggling with is making the content div dynamically adjust its height based on the remaining space between the header and footer. Adding a background to the container creates visibility issues with transparent elements like the header and footer.

If anyone can provide guidance or a template for achieving this structure, it would greatly help. Specific advice on styling the content div alone would also be appreciated.

EDIT:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>stretchy footer</TITLE>
<LINK rel="stylesheet" type="text/css" href="index.css" />
</HEAD>

<BODY>
<DIV id="container">

    <DIV id="header">
        <IMG src="./image/header2.png">
    </DIV>


    <DIV id="left">
        <DIV id="content">
            This is the div which needs to be stretched between header and footer.
        </DIV>
    test<BR>
    test<BR>
    test<BR>
    test<BR>
    test<BR>


    </DIV>

    <DIV id="right">
    t
    </DIV>

</DIV>
</BODY>
</HTML>

CSS style:


/* General */
* { margin: 0; padding: 0; border-style: none;}

*:hover, *:active, *:focus {
    outline: 0;
}

html {
    filter: expression(document.execCommand("BackgroundImageCache", false, true));
    line-height: 1;

    -moz-user-select: none;
    -moz-user-select: -moz-none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    user-select: none;
    -webkit-min-device-pixel-ratio:0;
    height: 100%;}
body {height: 100%;} /* safe crossbrowser font */
a {text-decoration: none; outline: none;}
a:active { 
    border: none;
    outline: none;}
.imagewrapper img {
    display: inline-block;
    width:100%;
    -ms-interpolation-mode:bicubic;
    image-rendering:-webkit-optimize-contrast;
    image-rendering:-moz-crisp-edges;
    image-rendering: optimizeQuality;
    zoom:1; *display: inline;}
/* End General */

.clear {
    clear: both;
}

#container {
    height: 100%;
    width: 1018px;
    margin: 0em auto -10em auto;
    position: relative;}

#left {
    display: inline-block;
    float: left;
    height: 100%;
    width: 950px;
    padding: 0em 2em 0em 1em;
    border: 1px solid brown;
    background: url(./image/main.png);
}
#left p {
text-align: justify;}

#right {
    float: right;
    width: 14px;
    border: 1px solid red;
}

Answer №1

When it comes to using CSS for laying out Div's, there are a variety of techniques to consider. Utilizing float: left / right and position:relative are good starting points. To fully address your query, it would be helpful to know the following:

Are you specifying a minimum height for the Div or do you want it to adjust based on the content size?

If you use outer divs as primary containers and populate them with inner divs set to "position:relative;" and "float:left / right" (whichever is needed), your page layout will expand according to the added content. If you have a maximum height and wish to incorporate scroll bar functionality, it's important to determine if the scrollbar tool has its own height settings (is it a separate div/panel?).

Another consideration is when using floats, including a div with clear:both style is necessary for proper line breaks. This should be placed after any sequence of elements that require a break. Checking compatibility in both IE and Firefox is crucial since they behave differently... neglecting to include

<div class="clear" runat="server">
element might result in a distorted appearance. Here is the CSS for the "clear" class:

.clear
{
  clear:both;
}

The following resources were useful when initially exploring these concepts:

CSS Position:

CSS Height:

Keep in mind that browsers like IE may vary from others. Attributes such as height="auto" may not be universally supported, so this must be considered.

Lastly, if you aim to achieve stretching effects, experimenting with attributes like width (e.g. height=99%) might be necessary. Typically, letting the main content section's height be determined by its contents works well. Surrounding all body-related content (excluding html body) with a div featuring relative positioning allows for adjusting column heights effectively. Setting all elements' heights to inherit or 100/99% could work, but adjustments may be required depending on the specific style elements used for achieving browser-neutral rendering.

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

The presence of an image within an HTML anchor is causing an unexpected artifact to

Currently, I am working on a simple header design, but there seems to be a strange issue with the anchors containing image tags. The problem can be seen in the screenshot below: Image Link Here is the HTML structure: <div class="block-content"> ...

JS receiving a reference to an undefined variable from Flask

I referenced this helpful post on Stack Overflow to transfer data from Flask to a JS file. Flask: @app.route('/') def home(): content = "Hello" return render_template('index.html', content=content) HTML <head> ...

The Android webview is blocking the display of a frame due to its X-Frame-Options being set to 'DENY'

Encountering an issue while attempting to display a Google calendar in a webview, an error is displayed: [INFO:CONSOLE(0)] "Refused to display 'https://accounts.google.com/ServiceLogin?service=cl&passive=1209600&continue=https://www.google.co ...

Generate a LESS variable using the content of an HTML element

Is there a thread discussing this that I might have missed? Please inform me if so! I am interested in creating and utilizing LESS variables that are based on the HTML content within a specific tag. For instance, suppose the HTML looks like this: <di ...

Chrome distorts the display:table when zoomed in

Consider this CSS snippet: .table { display:table; } .table-row { display: table-row; } .table-cell { display: table-cell; } Now, let's add some HTML to go along with it: <div class="table"> <div class="table-row"> ...

How can I create an image that spans the entire width of the screen, Swiper?

var swiper = new Swiper('.swiper-container', { pagination: { el: '.swiper-pagination', }, }); html, body { position: relative; height: 100%; } body { background: #eee; font-fami ...

Attempting to target modals in CSS using element IDs and class names is ineffective

Trying to implement dark mode in my app involves adding the following to the root element: <div id="dark"> Then, in CSS, styling it like this: #dark { background-color: #1A1A2E; } To customize each DOM element using classes, such as car ...

What is the best way to customize the appearance of a form element within an angular-schema-form schema without affecting the overall

Currently, I am in the process of constructing a form using the incredible angular-schema-form. Creating the form schema object has been a success so far. My goal is to configure all the form components within the schema using the x-schema-form property in ...

Guide on making a button for adding products to the shopping cart

I have put together this web page Check out the views.py code below: from django.shortcuts import render from django.http import HttpResponse from .models import Pizza # Managing views here. def index(request): pizzas = Pizza.objects.all().order_by( ...

The marquee's position is reset the first time text is loaded dynamically from an API

In my angular project, I'm implementing a marquee feature to display data fetched from an API. However, I've noticed a strange issue where after a page reload, the marquee starts from right to left but once it reaches the end of the div, it reset ...

Styling background images in Angular 4 with ngFor loop

I am having trouble with using background image URLs. I have an array of image URLs, how can I incorporate them into the background image URL? <div class="col-lg-3 col-md-3 col-sm-6" *ngFor="let course of courses"><a> </a><div c ...

Bootstrap version 5.3.0 has a unique behavior where dropdowns placed outside the collapsed area of the navbar will display the menu inside the navbar, rather than outside

Is there a way to fix the issue where the dropdown menu appears in the body of the navbar when it is collapsed? I have tried using attributes like data-bs-reference but couldn't find much information on how to resolve this. <nav class="navbar ...

Convince me otherwise: Utilizing a Sinatra API paired with a comprehensive JS/HTML frontend

As I embark on the journey of designing a social website that needs to support a large number of users, I have come up with an interesting approach: Implementing Sinatra on the backend with a comprehensive REST API to handle all operations on the website ...

Divs nested inside another div that result in horizontal scrolling

My query is similar to previous ones asked here: Horizontal Scrolling? and Horizontal scroll in DIV with many small DIV's inside (no text). However, I have the additional constraint of programmatically adding div elements without knowing their size u ...

Linkage Transformation

Seeking a solution for managing dynamic links. Imagine having a basic link like this: <a href="~/Test/Test.pdf" target="_blank">Test Dynamic Links</a> If there is a button or input that allows users to replace that link with another, how can ...

What is the most concise way to align one table row in the middle and another at the top?

Is there a way to align different rows in a table vertically with minimal code? I have a table with 3 rows, and I want the first two rows to be aligned vertically to the top, while the third row should be vertically aligned to the middle. If I try to def ...

Is there a way to implement a one-second delay before displaying a drop-down hover menu?

I've been trying to use the setTimeout function, but so far I haven't been able to figure out the correct way to do it. Any ideas on what I might be missing? JSFIDDLE $('.drop-down').click(function() { $(this).hide(); }); $(&apo ...

DataTables.js, the powerful JavaScript library for creating interactive tables, and its compatible counterpart

I'm currently making some changes to a dynamic table that require enabling a vertical scroll bar. As a result, I need to implement this vertical scroll bar mechanism on an existing table. The code in our project utilizes dataTables.js version 1.5.2 ...

Array of TextBoxes in HTML

After utilizing jQuery, I have managed to create an array of textboxes. <input type="text" name="salaries[]" value="100,000"> <input type="text" name="salaries[]" value="200,000"> <input type="text" name="salaries[]" value="300,000"> < ...

Arranging my form input fields in a neat vertical stack

@gnagy @Satwik Nadkarny I appreciate the help you both provided, and I wish I could give a plus to your responses (requires 15 rep sadly), but I have encountered another issue. After the first two text input fields, I added an additional input field for e ...