"How can I make one div stretch to the height of its parent while allowing another div to only fill the available height

I am currently designing a dashboard-like layout with two rows. The top row is not as important, but the second row is presenting a challenge. It consists of two divs with varying heights.

My goal is to have the left div fill the available space without overflowing or extending beyond the parent container, while allowing the right div to stretch the parent if it contains more content. Is this even achievable?

There's a slight complication to my query. I still need the ability to toggle these divs on and off using jQuery .slideToggle, and the left div often has lengthy content requiring a scroll.

I attempted to solve this using position: absolute and min-height, but toggling the left panel became clunky due to the min-height constraint. You can view a demonstration of this approach here

$(document).on("click", ".header", function() {
  let el = $(this).closest(".parent").find(".body");
  el.slideToggle();
})
.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -7.5px;
  margin-left: -7.5px;
}

.column {
  flex: 0 0 50%;
  max-width: 50%;
  padding-right: 7.5px;
  padding-left: 7.5px;
  box-sizing: border-box;
}

.parent {
  position: relative;
  display: flex;
  flex-direction: column;
}

.header {
  background: gray;
  border-radius: 10px 10px 0 0;
  text-align: center;
}

.body {
  background: #33333322;
  border-radius: 0 0 10px 10px;
  flex: 1 1 auto;
  min-height: 1px;
  padding: 1.25rem;
}

.responsive_table {
  overflow-x: auto;
}

table {
  width: 100%;
}

table tr td {
  border-bottom: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div class="row">
  <div class="column">
    <div class="parent">
      <div class="header">toggle</div>
      <div class="body">
        <div class="responsive_table">
          <table>
            <tr>
              <td>First line</td>
            </tr>
            <tr>
              <td>Second line</td>
            </tr>
            <tr>
              <td>3rd line</td>
            </tr>
            <tr>
              <td>4th line</td>
            </tr>
            <tr>
              <td>5th line</td>
            </tr>
            <tr>
              <td>6th line</td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </div>
  <div class="column">
    <div class="parent">
      <div class="header">toggle</div>
      <div class="body">
        <div>
          some text<br /> some text<br /> some text<br /> some text<br /> some text<br /> some text<br />
        </div>
      </div>
    </div>
  </div>
</div>

jsfiddle

Answer â„–1

Modify the behavior of stretching and filling using the display: flex; and flex-direction: column; properties:

.row {
  display: flex;
  flex-wrap: nowrap;
}

.column {
  flex: 1; 
  padding: 7.5px;
  display: flex;
  flex-direction: column;
  overflow: hidden; 
}

.parent {
  display: flex;
  flex-direction: column;
  height: 100%; 
}

.body {
  flex: 1; 
  overflow-y: auto; 
  padding: 1.25rem;
}

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

What is the best way to apply a className to a component using styled-components in React?

NavigationStyles.js import styled from 'styled-components'; export const Navigation = styled.navwidth: 100%; ; export const MobileNavMenu = styled.ul` height: 80px; .navbar_list_class { font-size: 2rem; background-co ...

Limiting Checkbox Selection and Controlling Input Box with JQuery: How to Choose Only 3 Checkboxes Simultaneously and Trigger Enable/Disable Function on Input Field

I am currently working on a feature that involves 6 checkboxes and 6 input fields. The idea is that when a user clicks on a checkbox, the corresponding input field will be enabled for data entry. If the checkbox is unchecked, the input field will be disa ...

What are some ways I can condense this code?

I have been working on improving my coding skills by learning jQuery. One of the tasks I tackled was creating a simple image showcase. However, the code I ended up with seems lengthy and not very efficient. Can anyone provide suggestions on how to enhance ...

Deactivating choice options when loading the page according to the MySQL query

I am seeking a solution for disabling certain options in a select input based on entries in a table. Specifically, I want to disable the time option if it has already been added twice to the table. For instance, if there are two entries for 1/18/2017 at 12 ...

Send the customer to a new page following an account creation error during submission

Whenever the user clicks on the "create" label, I have set up a redirection to another page. However, an issue arises when I activate the code snippet below for the redirection: <script> (function() { var REDIRECT_PATH = '/pages/become-a-p ...

Unlimited scrolling with external JSON data in AngularJS

I am struggling with implementing an infinite scroll in angularjs using a JSON file from an external site. I want the infinite scroll to trigger when the posts variable reaches 10, then call my function, increment the URL by +1, and load a new page. Here i ...

I need a way to ensure that the content I input into a form field stays saved even after I reload the page. It's

Within the fields for Firstname, Lastname, and Country, there is a unique feature on the Country field - an add button that allows users to input a country name to be stored in the database. After a user adds a country, the other fields become blank and ...

"Incorporate a bottom border into the hover, focus, and active states of the Bootstrap Wordpress navigation menu

I'm looking to enhance my menu navigation buttons by adding a 3px tall border at the bottom when they are hovered over, selected, or are the current menu item. I don't want a simple text underline effect, but rather a distinct border that matches ...

The ::before pseudo element is malfunctioning when used in the makeStyles function

I am currently utilizing the makeStyles function in React, but I seem to be facing an issue where the content within the ::before pseudo-element is not displaying. Strangely enough, when the content is an image it works fine, but text does not render. Jus ...

The cursor:pointer attribute fails to respond, along with the width and height properties not being recognized

Here is my custom CSS code: .uploadify { position: relative; margin-bottom: 1em; width:264px; height:54px; cursor:pointer; } Despite specifying the size in the attached HTML file (only accessible by administrators), the div does not ...

methods for concealing parse config credentials during client-side rendering

I have included Parse.initialize in my parse app's client-side code for login and signup. Is there a way to conceal this from being visible when the app is displayed so that it can't be easily inspected by unauthorized individuals? ...

Using jQuery to dynamically load custom post type data in WordPress upon clicking

Let me explain my current project setup. I have developed a custom post type called "People" and have created several individual posts within it. At the moment, I have successfully implemented a modal using JavaScript with static content. Instead of disp ...

Version 2.1 of Jquery - ensure that the element is destroyed only after both ajax calls have completed

I have a function with two ajax calls. I want to remove the .popup-loading element after both ajax calls are completed. What is the best way to achieve this? Function: // Function to create login/create user panel function createPopupUser() { var ...

Ensure that the <aside> elements span the entire width of their containing parent element

I am currently designing a website and I am aiming for a specific layout. Any advice on how to achieve this would be greatly appreciated. The header of the page consists of: a logo aligned to the left within an <a> tag 2 widgets placed in <asid ...

Integrate a three.js scene seamlessly into the background of a webpage

I have successfully created two separate HTML documents—one where a three.js scene is rendered and a basic HTML page. Now, my query is how to effectively combine them. My aim is to display a rotating green cube in the left corner and a moving red cube th ...

Refreshing a specific area on a webpage through the use of Ajax technology

I need to update a specific part of my webpage when a user clicks on the 'clear' button. I currently have some code that I borrowed from another answer I found on this site: $('.clear').click(function () { $.ajax({ url: "", ...

Creating a customizable navigation bar using only CSS

I'm currently working on creating a navigation bar using only HTML and CSS, without the need for JavaScript to open and close it. However, I've encountered an issue where the navigation bar remains open even after setting display: none or visibi ...

Sending PHP variables across different Bootstrap tabs without utilizing the href attribute

One challenge I am facing is trying to pass PHP variables using the <a> tag and the data attribute within the same PHP page while utilizing Bootstrap tabs: Here is an example of the HTML code (Bootstrap tab option): <a style='padding:20px;& ...

Is there a way to compel the browser or JavaScript to delete/disregard a cached file?

I've encountered an issue with my Javascript program that extracts data from a text file and displays it in a table. The problem arises when I update the text file - the changes don't reflect on the table because the browser is caching the file. ...

Get information from a specific text input after pressing the Enter key, among several text inputs with identical names and IDs

I am facing a challenge where I have multiple text inputs dynamically generated with the same id and name. My goal is to retrieve the data entered in a specific text input whenever a user hits the 'Enter' key in that field. For example, let&apos ...