Create a grid div that expands vertically to completely fill the available space

I am encountering an issue with my grid layout involving the menu, header, and content.

The problem lies in the fact that I want the content (blue box) to expand vertically within the grid element (yellow box). Currently, the grid stretches vertically, but the blue content inside it remains fixed.

Is there a solution to this problem that does not involve converting the entire grid structure to flexbox or using calc to manually adjust the height of the blue content?

.container {
  height: 100vh;
  display: grid;
  grid-template-rows: min-content 1fr;
  grid-template-columns: min-content 1fr;
  grid-template-areas: "menu header" "menu content";
  box-sizing: border-box;
  overflow: hidden;
}

.mainMenuWrapper {
  grid-area: menu;
  height: auto;
}

.headerWrapper {
  grid-area: header;
  height: auto;
}

.contentWrapper {
  grid-area: content;
  overflow-y: auto;
  height: auto;
  background-color: yellow;
}

.menu {
  height: 100vh;
  background-color: red;
  width: 50px;
}

.header {
  height: 80px;
  background-color: green;
}

.content {
  background-color: blue;
  width: 100%;
  height: ???
}
<div class="container">
  <div class="mainMenuWrapper">
    <div class="menu">
      menu
    </div>
  </div>
  <div class="headerWrapper">
    <div class="header">
      header
    </div>
  </div>
  <div class="contentWrapper">
    <div class="content">
      content
    </div>
  </div>
</div>

Image: https://i.sstatic.net/MnFkc.png

JSFiddle link: https://jsfiddle.net/the2sj1n/3/

Answer №1

Applying height: 100% to the blue box with the class .content will solve the issue.

body {
  margin: 0; /*Resetting default browser margins*/
}

.container {
  height: 100vh;
  display: grid;
  grid-template-rows: min-content 1fr;
  grid-template-columns: min-content 1fr;
  grid-template-areas: "menu header" "menu content";
  box-sizing: border-box;
  overflow: hidden;
}

.mainMenuWrapper {
  grid-area: menu;
  height: auto;
}

.headerWrapper {
  grid-area: header;
  height: auto;
}

.contentWrapper {
  grid-area: content;
  overflow-y: auto;
  height: auto;
  background-color: yellow;
}

.menu {
  height: 100vh;
  background-color: red;
  width: 50px;
}

.header {
  height: 80px;
  background-color: green;
}

.content {
  background-color: blue;
  width: 100%;
  height: 100%; /*Modification made here*/
}
<div class="container">
  <div class="mainMenuWrapper>
    <div class="menu">
      menu
    </div>
  </div>
  <div class="headerWrapper">
    <div class="header">
      header
    </div>
  </div>
  <div class="contentWrapper">
    <div class="content">
      content
    </div>
  </div>
</div>

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

Is it possible to access the CSS property from an external CSS file even when inline styles are used?

Is there a way to retrieve the css property from an external source using JavaScript or jQuery even if inline styles are applied to the same element? Here's an example: <div id="my" style='left:100px'>some content</div> <styl ...

Manage a frame directly from the parent page

I am faced with a situation where I have a web page with two textboxes and a button. Unfortunately, I am unable to alter the contents of this page in any way. My goal is to find a way to automatically populate the first textbox with some text when the pag ...

Create engaging text animation by transitioning from horizontally displayed text to vertically displayed text with the letters standing upright using An

I'm trying to create an animation where an acronym is displayed horizontally in the middle of the screen and then flips vertically. The challenge I'm facing is rotating individual letters once they are vertical so that the text reads from top to ...

Having trouble with a switch statement in Javascript that is unable to find a case for "none."

In my code, I am checking to see if there is a ball in a specific map point and then changing the color of the pixels where the ball is located to match the color of the ball. Here is my code snippet: function UpdateColorInMapPoints(mapPointIndexs) { / ...

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 ...

What separates $(document).ready() from embedding a script at the end of the body tag?

Can you explain the distinction between running a JavaScript function during jQuery's $(document).ready() and embedding it in the HTML within script tags at the bottom of the body? Appreciate your insights, DLiKS ...

Position the label to the left of the form-switch using Bootstrap

I have been struggling to align the label to the left of my switchbox. Despite searching through stackoverflow and other websites, I haven't been successful in achieving the desired alignment. Here is a trimmed down version of the code for reference: ...

Is there a way to superimpose multiple PNGs and ensure that each one is clickable within its designated area?

I am looking to implement a interactive image system for dynamically generated content. The image includes a background image and various grey-scale mask images. Background Image: https://i.sstatic.net/NWzQ1.jpg (source: goehler.dk) Masks: https://i.ss ...

Tips for creating responsive scrollable columns in an HTML table with Bootstrap

I'm not a professional web designer. I attempted to create a web layout with scrollable columns containing data in anchor tags that are loaded dynamically. To achieve this, I created an HTML table structure along with a stylesheet. Here is the source ...

Is there a way to add a delay when opening all of the links on my web page

Has anyone experimented with implementing time delays on global links before? I am aiming to have all my links open with a delay in order to create a smoother transition between pages for an artistic touch. However, I seem to be encountering some issues ma ...

Utilizing Bootstrap to display selected portions of the list content

I am working with a select element that looks like this: jQuery('.my-select').selectpicker(); .list_img{ width: 30px; height: 30px; } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script ...

Tips for saving an array of objects in local storage and transferring it from one file to another

Recently delving into the world of localstorage, I've encountered an issue while attempting to store JSON data in one file and retrieve it in another. The JSON data below was fetched from a URL, and my goal is to obtain all the feed objects in the oth ...

How is it possible that the form already comes with data filled in that I didn't input myself

I am currently working on a website using cakephp. Strangely, when I load the login form, both the username and password fields are already prefilled. The interesting part is that this information is not hardcoded anywhere in the form or controller files. ...

The checkbox tab index fails to function properly when set to hidden with a custom design

I have implemented a custom design for a checkbox using CSS. label { position: relative; margin-bottom: 0.5em; } .input-field { width: 100%; border: 1px solid #ecf0f1; padding: 0.5em; } input[type="radio"], input[type="checkbox"] { display: ...

What is the best way to notify the user about the input in the textbox?

Imagine you have a button and an input field. How could you notify the user of what is in the input field when the button is pressed? Please provide a simple explanation of your code. ...

Adjusting Renderer Size in ThreeJS for Fullscreen Display

After creating a ThreeJS application designed for a 4:3 layout with multiple buttons and features, I decided to enable Fullscreen mode using THREEx.Fullscreen.js. Although the Fullscreen mode is functioning properly, a new issue arose - the renderer size(x ...

Navigating a Multi-Page Website with Sleek Scrolling

I've been searching for a solution everywhere but haven't had any luck. I'm trying to implement a smooth scroll effect that works seamlessly across multiple pages. For instance, the smooth scroll effect is present on the homepage with naviga ...

Are the site-wide navigation links working on one page but not the other?

Currently, I am in the process of constructing a website on rails and have successfully integrated a site-wide navigation bar to display on all pages. However, an issue has arisen where the navbar is visible on both pages, yet the links and hover effects a ...

Excessive spacing in the <td> elements - TABLE

I am encountering some problems with my table layout. The spacing between the field names and text boxes appears to be too large. Could there be mistakes I'm making that are causing this issue? How can I minimize the gaps? Please refer to the image b ...

What steps should I take to modify the URL using the SELECT tag?

Having a bunch of SELECT tags in place <select id="url"> <option id="url1" >url 1</option> <option id="url2" >url 2</option> </select> <button onclick="go()">GO</button> Followed by the associated scrip ...