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

Enhancing the Search Form Minimum Width in Bootstrap 4 Navbar

Looking for a way to create a search form with a width of 100% and a minimum width within a Bootstrap 4 navbar? Check out my code snippet here. <nav class="navbar navbar-expand-md navbar-light bg-faded"> <a href="/" class="navbar-brand">Brand& ...

Incorporating custom HTML5 player to watch Youtube videos on my website

I'm trying to display YouTube videos on my website using a simple video tag. I've managed to retrieve the encoded url of the video from the page source and successfully download it through IDM, but when I try to use this URL as the source for an ...

Encountered SyntaxError: An unexpected token has been found while integrating leaflet with flask

Despite adding all necessary scripts and configuring my API_KEY in config.js, I keep getting an error message saying "Uncaught SyntaxError: Unexpected token." I have double-checked my API key multiple times, and it seems to be correct. Here is a snippet f ...

How can jQuery determine if multiple selectors are disabled and return true?

I am currently working on a form in which all fields are disabled except for the "textarea" field. The goal is to enable the "valid" button when the user types anything into the textarea while keeping all other inputs disabled. I initially attempted using ...

Utilizing JavaScript, create a dynamic grid gallery with Div Spin and expand functionality

I am looking to create a unique effect where a div rotates onclick to reveal a grid gallery on the rear face. Starting this project feels overwhelming and I'm not sure where to begin. <ul class="container-fluid text-center row" id=" ...

Obtaining table data and HTML elements using the correct code - Selenium and Python

I've been attempting to extract the ticker symbol, stock name, price, sector, and market cap columns from this website. I'm facing challenges in identifying the correct HTML elements using the appropriate code. Although I've used Selector Ga ...

Why isn't my margin: auto code centering correctly?

My current struggle involves centering a div within the document. While I have successfully achieved horizontal centering, vertical centering remains elusive: width: 950px; height: 630px; background: #FFFFFF; margin: auto; Is it not expected that margin: ...

What is the best way to ensure that a child div can expand to fit within the scrollable area of its parent div

I am facing an issue with a parent div that changes size based on the content inside it. When the content exceeds the initial size, causing the parent to scroll instead of expanding, I have a child div set to 100% width and height of the parent. However, t ...

Verify whether a div element is styled in a specific manner

Upon initial load of my website, if the page is maximized or in fullscreen mode, the comBrand div will have specific CSS properties applied. However, during a resize event, I use the .css() function to adjust the properties of this element so it doesn&apos ...

How can I determine the mouse's location relative to the bottom right corner of the

Currently, I am in the process of writing jQuery code that will detect if the mouse is positioned near the bottom or right side of a window, and then adjust the tooltip's position accordingly. This becomes crucial because the table in which these tool ...

Updating the Hero Image

Scenario: In my project directory, under Product -> src -> static -> ostatic [ there are two folders named css and images ] -> images -> where all the images can be found. I am using bootstrap and attempting to set a background-image for j ...

Stuck with the Same Theme in the AppBar of material-UI?

Currently, I am attempting to modify the theme of a material-UI AppBar by utilizing states. Strangely enough, although the icons are changing, the theme itself is not. If you'd like to take a look at the code, you can find it here: https://codesandbo ...

Attempting to establish a means to switch between languages

Currently, I am in the process of implementing a language switch feature for a website project that I am currently working on. This feature will allow users to seamlessly switch between English, Latvian, and Norwegian languages. To achieve this functionali ...

Is it possible to stop the manipulation of HTML and CSS elements on a webpage using tools similar to Firebug?

How can we prevent unauthorized editing of HTML and CSS content on a webpage using tools like Firebug? I have noticed that some users are altering values in hidden fields and manipulating content within div or span tags to their advantage. They seem to be ...

The seamless integration of an HTML dropdown list in a form with a PHP email feature

Take a look at this HTML code snippet with PHP integration. How can I achieve this? I'm fairly new to coding. I'm currently developing a contact form that includes a dropdown menu for selecting an email address related to a specific physician. I ...

Is There a Workaround for XMLHttpRequest Cannot Load When Using jQuery .load() with Relative Path?

My current project is stored locally, with a specific directory structure that I've simplified for clarity. What I'm aiming to do is include an external HTML file as the contents of a <header> element in my index.html file without manually ...

Compel the system to handle the file as if it were an

I am currently showcasing programming files on a website in plain, raw text format. I have now decided to implement syntax highlighting using HTML. While it has enhanced the appearance and functionality of the files, there is one issue - I need to create a ...

The width of the Div element is not following the specified dimensions, and it also has an unspecified margin

Check out my code snippet at: http://jsfiddle.net/8z4aw/ I'm trying to create a table-like layout using div elements, but for some reason the browser is not respecting the specified widths and seems to be adding an unwanted right margin. Where is thi ...

A quick guide on automatically checking checkboxes when the user's input in the "wall_amount" field goes over 3

I'm looking to have my program automatically check all checkboxes (specifically "Side 1, Side 2, Side 3 and Side 4") if the input for wall_amount is greater than 3. Is there a way to achieve this? I attempted lines 10-12 in JavaScript without success. ...

I'm having some trouble with my jQuery.get() function in the javascript Saturday(), can anyone help me figure out what I'm doing wrong?

Can anyone help me troubleshoot my jQuery.get() method in the saturday() JavaScript function? Here is the code snippet I have been working on. This is what I have in my index.html file: <html> <head> <title>jVectorMap demo</title> ...