Ways to expand the height of a child element within a flex container that has been

I am facing an issue with stretching the children of a column flexbox container. While I can stretch one of the flexbox child elements, I am unable to stretch its nested children. Below is an example where .flex-child-2-child and .flex-child-2-child-child should vertically fill the space within .flex-child-2:

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  border: 4px solid green;
}

.flex-child-1 {
  width: 100px;
  background-color: SteelBlue;
}

.flex-child-2 {
  flex: 1;
  background-color: LightSeaGreen;
}

.flex-child-2-child-child,
.flex-child-2-child {
  height: 100%;
}

.flex-child-2-child-child {
  background-color: Tomato;
  display: flex;
  width: 100%;
}
.flex-child-2-child-child > div {
  flex: 0 1 auto;
  border: 1px solid yellow;
  height: 100%;
  width: 100px;
}
.flex-child-2-child-child > div + div {
  flex: 1;
}
<div class="flex-child flex-child-1">
  Test
</div>
<div class="flex-child flex-child-2">
  <div class="flex-child-2-child">
    <div class="flex-child-2-child-child">
      <div>Hello</div>
      <div>World!</div>
    </div>
  </div>
</div>

One solution could be using the height property instead of min-height on the body element, but this would cause long content to overflow out of the body container.

body {
  display: flex;
  height: 100vh;
  flex-direction: column;
  border: 3px solid green;
}

.flex-child-1 {
  width: 100px;
  background-color: SteelBlue;
}

.flex-child-2 {
  flex: 1;
  background-color: LightSeaGreen;
}

.flex-child-2-child-child,
.flex-child-2-child {
  height: 100%;
}

.flex-child-2-child-child {
  background-color: Tomato;
  display: flex;
}

.flex-child-2-child-child>div {
  flex: 0 1 auto;
  border: 1px solid yellow;
  width: 100px;
}

.flex-child-2-child-child>div+div {
  flex: 1;
}
<div class="flex-child flex-child-

1">
  Test
</div>
<div class="flex-child flex-child-2">
  <div class="flex-child-2-child">
    <div class="flex-child-2-child-child">
      <div>Hello</div>
      <div>World!
        <p></p>
        [ ... ]
        <p></p>
      </div>
    </div>
  </div>
</div>

Answer №1

Apply the following styles to .flex-child-2:

flex: 1; display: flex; flex-direction: column;

Also, add

display: flex; flex-direction: column; flex: 1;
to both .flex-child-2-child-child and .flex-child-2-child in order to stretch the elements.

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.flex-child-1 {
  width: 100px;
  background-color: SteelBlue;
}

.flex-child-2 {
  flex: 1;
  background-color: LightSeaGreen;
  display: flex;
  flex-direction: column;
}

.flex-child-2-child-child,
.flex-child-2-child {
  /* height: 100%; */
  display: flex;
  flex-direction: column;
  flex: 1;
}

.flex-child-2-child-child {
  background-color: Tomato;
}
<div class="flex-child flex-child-1">
  Test
</div>
<div class="flex-child flex-child-2">
  <div class="flex-child-2-child">
    <div class="flex-child-2-child-child">
      Hello Word!
    </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

Tips for designing a horseshoe-inspired meter using CSS

  I want to create a horseshoe-shaped gauge using CSS that resembles the image below:     My attempt involved creating a circle and cutting off the bottom, similar to the technique demonstrated in this fiddle: http://jsfiddle.net/Fz3Ln/12/   Here& ...

The NVDA screen reader is unable to detect visually hidden text

In the code snippet below, part of a table is shown where some text is meant to be displayed visibly and some should be visually hidden. However, it seems that the screen reader does not detect the visually hidden text when hovering over it with a mouse. T ...

Mastering the Art of Content Swapping in SPA

Hey there! I'm in the process of creating a webpage using tornado io and incorporating various graphs. To add some single page app magic, I decided to swap out content within a div like so: <div id="chartType"> Chart goes here</div> <a ...

Discover the method for retrieving the value of a toggle-style checkbox

I am currently working with a toggle switch checkbox and I need to extract its value using JavaScript or jQuery when the state changes. Based on this value, I aim to highlight the text of the label associated with the toggle switch, whether it's opti ...

When using VueJS to load an SVG file based on a variable within a for loop and utilizing v-html, the result returned is "[

I'm faced with a challenge of loading SVGs saved in separate files based on the content within a loop. Upon page load, what I see is: Hey there, check out my code snippet below: <div v-for="(rec, index) in stats" :key="index" > <div ...

What are the best methods for visually comparing two HTML documents?

In the process of developing a Windows Forms application, my goal is to compare two HTML documents. The initial document is sourced externally and contains structural errors. To address this, an algorithm is utilized to optimize the HTML text, resulting in ...

using a tag in flex can disrupt the arrangement of the box's design

What could be the reason for this issue? Is it possible to make the hyperlink appear inline with the rest of the text? .test { padding: 25px; display: flex; height: 100%; text-align: center; font-size: 25px; font-weight: 600; ...

Leveraging image values for selecting an image from a collection and showcasing it (Javascript)

I have a collection of images that I want to enlarge upon clicking. Here is what I currently have: <div class="gallery"> <div> <img src="content/imggallery/img1.jpg" class="oldimg" value="0"> </div> ...

Convert form data into a JSON object utilizing JQuery and taking into account nested JSON objects

Currently, I am facing an issue while extracting data for submission using the jQuery `serializeArray()` function. This function works efficiently by providing an array of { name: value } objects, where the name corresponds to the elements in the form. How ...

Developing a perpetually scrolling container within a webpage

I am attempting to implement a scrollable div on my webpage that can continuously load content. I am currently using the following code snippet for this --> http://jsfiddle.net/cyrus2013/Qq85d/ $(document).ready(function(){ function loadMoreContent() ...

Exploring the World of Html

I'm struggling with an HTML problem related to a web programming class I'm taking. The assignment involves creating a video game using HTML and JavaScript, where an image moves randomly on the screen and the player must click on it as many times ...

Guide to updating information inside of script tags in html using javascript

Within my HTML, there is a script tag that looks like this: <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "VideoObject", "name": "Title", "description": "Video descrip ...

blending the transition from dark image to black background

Utilizing the CSS below: #divPic { height: 32pc; background-image: url('https://wallpaperscraft.com/image/black_black_white_bone_time_game_noise_74543_4000x2248.jpg'); background-repeat: no-repeat; background-position: left center; b ...

Utilizing XSLT 1.0 to encase text and elements within paragraphs

After successfully solving a problem using XSLT 2.0, I now face the challenge of achieving the same outcome in XSLT 1.0 due to the requirement of using a processor compatible with XSLT 1.0. My task involves handling various types of XHTML and XML, each wi ...

Highlighting the selected tab with an active class

Currently in the process of learning angularJs, I am still new to it and attempting to dynamically add an active class to the recently clicked tab. Within my interface, there are four tabs: insert, view, update & delete. My goal is to apply the active ...

Ensuring Proper Alignment of Headers in CSS

I'm struggling to align my header correctly. Despite getting close in Internet Explorer, it looks terrible in Firefox with the code below. I've scoured forums for solutions but the more I try to fix it, the worse it looks. All I want is for heade ...

Is there a way to obtain the "rotated" coordinates of a mouse click within a canvas element?

Exploring New Features Within my image editing software, there is a canvas where users can draw shapes. These shapes are sent to a server and added to an XML file, which is then returned to the client for display. Now, I am looking to enhance the program ...

Is it possible for me to use @import to selectively choose what I need and disregard the rest?

If I am utilizing SASS and wish to incorporate a significant portion of another existing stylesheet, whether it is in SASS or CSS format, I have the option to import that particular sheet using @import, then employ @extend to apply some of its rules. Is ...

Issues with styling classes using global SCSS in React are causing unexpected behavior

Currently, I am working on a React project that includes the use of SASS for styling purposes. While implementing modular CSS in my components, I have encountered an issue with applying styles from a main.scss file in my Layout.js component. The unique a ...

The function setCustomValidity() will continue to display even after the form has been successfully filled out

My form is very simple and I am trying to validate it using the required attribute: <form name="form"> <label for="Header">Title</label> <input type="text" class="span5" name="Header" ng-model="Message.header" placeholder="Title" on ...