Generate a container element that occupies the remaining space on the screen under a header of adjustable height

I'm trying to create a layout where the header height can vary, but the footer has a fixed height. I want the left nav and content sections to fill the screen height, with the left nav having a fixed width and the content taking up the remainder.

Is there a way to achieve this using just HTML and CSS, without any JavaScript?

You can see an example here: JSFiddle example (Full code provided below)

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <style type='text/css'>
    * {
    padding: 0;
    margin: 0;
}
html, body{
    overflow: hidden;
    width: 100%;
    height: 100%;
}
p {
    line-height:1em;
}
ul {
    margin-left : 2em;
    list-style: none;
}
header {
    width: 100%;
    background-color:red;
    border-bottom-width: 0.25em;
    border-bottom-color: blue;
    border-bottom-style: solid;
}
nav {
    position:absolute;
    width: 15em;
    top:0;
    left:0;
    bottom:3.25em;
    background-color:gray;
    overflow:auto;
}
section {
    position:absolute;
    top:0;
    left:15em;
    bottom:3.25em;
    right:0;
    padding:0.25em;
    background-color:yellow;
    border-left-width: 0.25em;
    border-left-color: blue;
    border-left-style: solid;
    overflow:auto;
}
footer {
    position:absolute;
    bottom:0;
    width: 100%;
    height: 3.25em;
    text-align:center;
    background-color:green;
}
  </style>

</head>
<body>
  <header>
    <img src="http://www.luzchem.com/images/up1.jpg" style="vertical-align: top;" />
    <p>Menu and Search</p>
</header>
<div style="position:relative; height:100%;">
<nav>
    <ul>
        <li><a href="#">Line 1</a>
        </li>
        <li><a href="#">Line 2</a>
        </li>
        <li><a href="#">Line 3</a>
        </li>
    </ul>
</nav>
<section>
    <p>Body</p>
</section>
<footer>
    <p>5509 Canotek RD, Unit 12, Ottawa Ontario, Canada, K1J9J9
        <br />Phone: (613) 749-2442 Fax: (613) 749-2393 Toll Free: (800) 397-0977
        <br /><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81f2e0ede4f2c1edf4fbe2e9e4ecafe2eeec">[email protected]</a>?subject=General%20Inquiry&body=What%20do%20you%20want%20today%3F"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4033212c2533002c353a2328252d6e232f2d">[email protected]</a></a>
    </p>
<div style="position:relative; bottom:0;"> <span style="text-align:right; float:right; margin-right:1em;">Copyright &copy; 2012 Luzchem Research Inc.</span>
        <div style="text-align:left; float:left; margin-left:1em;"> <a href="company_info.php">Company Info</a>
 <a href="">Link_2</a>
 <a href="">Link_3</a>
        </div>
    </div>    
</footer>
</div>
</body>
</html>

Answer №1

Check out this potential solution: https://jsfiddle.net/3zgvrde8/

Here is the HTML code:

 <header>
    <img src="http://www.luzchem.com/images/up1.jpg" style="vertical-align: top;" />
    <p>Menu and Search</p>
</header>
<div style="position:relative; display:block;height:100%">
<nav>
    <ul>
        <li><a href="#">Line 1</a>
        </li>
        <li><a href="#">Line 2</a>
        </li>
        <li><a href="#">Line 3</a>
        </li>
    </ul>
</nav>
<section>
    <p>Body</p>
</section>
</div>
<footer>
    <p>5509 Canotek RD, Unit 12, Ottawa Ontario, Canada, K1J9J9
        <br />Phone: (613) 749-2442 Fax: (613) 749-2393 Toll Free: (800) 397-0977
        <br /><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbb8aaa7aeb88ba7beb1a8a3aea6e5a8a4a6">[email protected]</a>?subject=General%20Inquiry&body=What%20do%20you%20want%20today%3F"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93e0f2fff6e0d3ffe6e9f0fbf6febdf0fcfe">[email protected]</a></a>

    </p>
<div style="position:relative; bottom:0;"> <span style="text-align:right; float:right; margin-right:1em;">Copyright &copy; 2012 Luzchem Research Inc.</span>

        <div style="text-align:left; float:left; margin-left:1em;"> <a href="company_info.php">Company Info</a>
<a href="">Link_2</a>
 <a href="">Link_3</a>

        </div>
    </div>    
</footer>

This is the CSS code:

* {
    padding: 0;
    margin: 0;
}
html, body{
    overflow: hidden;
    width: 100%;
    height: 100%;
}
p {
    line-height:1em;
}
ul {
    margin-left : 2em;
    list-style: none;
}
header {
    width: 100%;
    background-color:red;
    border-bottom-width: 0.25em;
    border-bottom-color: blue;
    border-bottom-style: solid;
}
nav {
    top:0;
    left:0;
    bottom:3.25em;
    background-color:gray;
    float:left;
    width: 15em;
    display:block;
    height:100%
}
section {
    display:block;
    left:15em;
    padding:0.25em;
    background-color:yellow;
    border-left-width: 0.25em;
    border-left-color: blue;
    border-left-style: solid;
    overflow:auto;
    width: 100%;
    height:100%
}
footer {
    clear:both;
    bottom:0;
    width: 100%;
    height: 3.25em;
    text-align:center;
    background-color:green;
    position:absolute;
}

If you have any questions or need further assistance, feel free to ask.

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

Insert a gap between the two columns to create some breathing room

Does anyone know how to create spacing between columns in an HTML table without affecting the rows? In my table, each column has a border around it: <table> <tr> <td style="padding:0 15px 0 15px;">hello</td> <td style=" ...

"Blank Canvas: Exploring the Void in Laravel Blade Templates

This is the route that I am using Route::get('login', function(){ return View::make('admins.login'); }); In this code, I have created a admins/login.blade.php file to handle the login view. <!doctype html> <html> < ...

Utilize CSS to ensure that the hover effect of the main navigation remains active even when the mouse hovers over the sub-menu

Is there a way to make the hover state in navigation items persist when the mouse hovers over a sub-menu? Currently, when hovering over a top-level nav item, the link color changes to white and background turns black, but this reverts back once the mouse m ...

Using a width of 100% with the display inline-block property does not function as intended

Is there a way to have both a checkbox and text input in one line, with the text input being responsive? I attempted to use display: inline-block, which worked for keeping them in the same line, but I'm having trouble making the text input fill the re ...

Alter the font color upon clicking the menu using jQuery

When I click on the menu and sub-menu items, I want to change their colors along with their parent. You can see an example of how I want it to work here. However, currently, when I click on a sub-menu item, the color of the parent menu item gets removed. ...

Guide to applying conditional styling to Material-UI TextField

After creating a custom MUI TextField, I implemented the following styling: const CustomDisableInput = styled(TextField)(() => ({ ".MuiInputBase-input.Mui-disabled": { WebkitTextFillColor: "#000", color: "#00 ...

Having trouble unselecting the previous item when selecting a new item in Reactjs

I have a list of items and I want to change the background color of the currently selected item only. The previously selected item should deselect. However, at the moment, all items are changing when I click on each one. Can anyone help me solve this issue ...

Tips for adding a text input field within a dropdown menu

Could someone provide guidance on how to place an input text box within a dropdown without using bootstrap? I came across this image showing what I am looking for: https://i.stack.imgur.com/f7Vl9.png I prefer to achieve this using only HTML, CSS, and Jav ...

Dynamic text displayed on an image with hover effect using JavaScript

Currently, I am in the process of developing a website for a coding course that is part of my university curriculum. The project specifications require the use of JavaScript, so I have incorporated it to display text over images when they are hovered over ...

CSS division nested within the center float division

In my attempt to design a 3-column home layout, I have successfully styled the center, left, and right sections. However, I am facing difficulty in placing two sliders within the middle class. My goal is to have slider1 positioned on top inside the middle ...

Tips on how to transform an <input type="text"> element into a <tr> element using jquery

I am currently working on updating a row using jQuery Ajax. Whenever the Edit button is clicked, it switches the <tr> element to <input type='text'>. I have utilized the .Change method which triggers successfully, but my goal is to r ...

Adjusting the tab size and space size to their default settings within VSCode

I'm currently facing an issue with my VSCode setup. I am trying to configure the space size to be equal to 1 and tab size to be equal to 2 as the default for every project. However, despite my efforts, it keeps reverting back to spaces: 4 for each new ...

When adding classes using Angular's ng-class, CSS3 transitions are not activated

After creating a custom modal directive in Angular, I am encountering an issue with the transition animation not working as expected. Within my directive's isolated scope, there is a method called toggleModal() that toggles the modalState between true ...

What is the best way to add a CSS link if a request is not made using AJAX?

My webpage, 'foo.html', retrieves data from a database using AJAX ('ajax.html?options=option1') to populate a table. The table is styled nicely with CSS that is linked to 'foo.html'. However, I also want the ajax.html page to ...

AJAX loading footer content before images are fully loaded

I am a beginner when it comes to ajax and I'm facing an issue where the footer loads before the images, causing the images to overlap the footer. The problem is illustrated in the image below. <!doctype html> <html lang="en"> <head ...

What is the process for transferring selections between two select elements in aurelia?

I am attempting to transfer certain choices from select1 to select2 when a button is clicked. Below is my HTML code: <p> <select id="select1" size="10" style="width: 25%" multiple> <option value="purple">Purple</option> &l ...

Order of tabs, dialog, and forms customization using Jquery UI

I'm currently working on a jquery dialog that contains a form split into multiple tabs. In order to enhance keyboard navigation, I am looking for a way to make the tab key move from the last element of one tab to the first element of the next tab. Cur ...

Modifying the order of Vuetify CSS in webpack build process

While developing a web app using Vue (3.1.3) and Vuetify (1.3.8), everything appeared to be working fine initially. However, when I proceeded with the production build, I noticed that Vue was somehow changing the order of CSS. The issue specifically revol ...

When the page is refreshed, the value bounces back and forth between

I've encountered a strange issue on my page with 6 textboxes. Whenever I enter values into these text boxes and then refresh the page, the values seem to jump to the next textbox (the one after the next). For example, if I enter values as follows: [ ...

The Scrapy CSS selector is not fetching any prices from the list

Having trouble with the price CSS-selector while scraping an interactive website using Scrapy. Check out the HTML screenshot I captured: https://i.stack.imgur.com/oxULz.png Here are a few selectors that I've already experimented with: price = respon ...