When implementing flex-grow 1 on a flex box, the remaining space is not being filled as expected

I am struggling to make the green div fill the remaining space of a flex box container. My goal is to have the top row (blue) adjust its height based on content, and then have the row below (green) take up the rest of the space. However, it seems like the flex rows are splitting evenly down the container instead. I've tried setting the containing div's height to 200px, as well as adding another container with a height set to 100%, but nothing seems to work. I've also made sure to use the flex-grow property on the second row. Flexbox can be quite confusing at times - any assistance would be greatly appreciated! Thank you.

P.S. The HTML code snippet below doesn't show the first line of my HTML, which should be contained within the following div:

<div class="rmCtrlList_item"

https://i.sstatic.net/4wjxu.png

.rmCtrlList_item {
  width: 80vw;
  margin: 3vw 8.5vw;
  height: 200px;
  background-color: $primary-color;
  border-radius: 10px;
  padding: 5px;
  display: flex;
  flex-flow: row;
  flex-wrap: wrap;
  // ROWS
  &_row {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
  #row-1 {
    //max-height: 20px;
    background-color: blue;
  }
  #row-2 {
    flex-grow: 1;
    align-items: center;
    justify-content: center;
    background-color: green;
  }
  // COLUMNS
  &_col {
    text-align: left;
    flex-direction: column;
  }
  #col-1b {
    flex-grow: 1;
  }
}
<div class="rmCtrlList_item">

  <div class="rmCtrlList_item_row" id="row-1">

    <div class="rmCtrlList_item_col" id="col-1a">
      <a href="lights.html"><i class="icon__panel-2 fas fa-lightbulb"></i></a>
    </div>

    <div class="rmCtrlList_item_col" id="col-1b">
      <a href="lights.html">
        <h1 class="panel__title">Lights</h1>
      </a>
    </div>

    <div class="rmCtrlList_item_col" id="col-1c">
      <a href="lights.html"><i class="icon__enlarge fas fa-plus-circle"></i></a>
    </div>

  </div>

  <div class="rmCtrlList_item_row" id="row-2">
    div to fill remaining space
  </div>
</div>

Answer №1

Would using flex-direction and the code below be a good solution? The green section will automatically fill the remaining space if you set its height to 100%

.container{
  display: flex;
  flex-direction: column;
  width: 200px;
  height: 300px;
  border: 1px solid black;
}

.blue{
  width: 100%;
  height: 90px; /*change only blue's height size, green will be filled automatically*/
  background: blue;
}

.green{
  width: 100%;
  height: 100%;
  background: green;
}
<div class="container">
  <div class="blue"></div>
  <div class="green"></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

Retrieving details of a row in Codeigniter using a link with a foreach loop

After nearly a month of trying, I am still unable to figure out how to extract the "details" for each row from my table in the view. The table is populated using a foreach loop and I want to display these details on another page when clicking the link labe ...

Tips for creating a unique custom UI headline using ReactJS, CSS, and bootstrap

Looking to create a design that is responsive in ReactJS using Bootstrap or CSS if needed. I need assistance with placing separators between columns and ensuring the values of each label are aligned in the same column but on the next line. The layout shoul ...

On iOS devices, background images may not appear in the Home Screen after being added

My CSS code looks like this: #thumbnail { background-image: url(bla.jpg), background-size: cover, background-repeat: no-repeat; background-position: 50% 50%; } While it displays fine on iOS Safari and other platforms, the image does not s ...

What are the steps for displaying CKeditor's formatted text from a content management system on a Next.js website?

Presently, my method entails utilizing : <div dangerouslySetInnerHTML={{ __html: article.content }}></div> to display the formatted text retrieved from a CKEditor input field within a Strapi CMS backend. Is there an alternative approach to ach ...

What is the best way to rearrange the elements in a database after they have been displayed?

I have a feature on my website where you can enter text into a textbox and then click a button to save it in a database. The saved entries are displayed along with buttons for deleting an entry and moving it to the top of the list. <?php $resultset2 = ...

Try triggering transitions on all elements by hovering over any CSS element

I am currently in the process of developing a website, and for the header section, I have decided to use a table format where each column represents a different section. The top row will feature a picture link, while the bottom row will display the name of ...

The carousel top position in Bootstrap 4 is not functioning properly

I am struggling to get the teal rectangle to move to the top of the carousel. I have set my carousel to have a position relative and my teal rectangle to have a position absolute with top="0", but it doesn't seem to be working properly. Instead of mov ...

Is there a way to remove the entire row if I dismiss a bootstrap alert?

Hey there! I'm having a little issue with an alert in a row-fluid. Curious to see? Check out my fiddle. So, when I click the "x" button to dismiss the alert, the row is still visible. Any idea how I can make the entire row disappear when I dismiss it? ...

What is the best way to retrieve the textbox value when its associated checkboxes have been selected?

Upon selecting a checkbox and entering data into the linked textbox, upon submission I aim to reveal a form showcasing both the entered text and which checkboxes were selected. ...

Calculating dimensions for parents and their children

Could someone please explain to me why the size of #child is different from that of #parent? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.or ...

Using JavaScript functions to modify the style of the DOM

Is there a way to change the style of a dom element using JavaScript when only the element id and style value are passed as parameters, without passing the actual style parameter itself? For example, is it possible to use the id "first" and set the color ...

Exploring jQuery's ability to retrieve CSS values

Is there a way to use jQuery to read a specific CSS value from a class? The situation is as follows: HTML: <div class="box"></div> CSS: .box { margin-top: 100px; } I want to determine if the .box class has a margin-top of 100px in order t ...

Updating HTML5 localStorage value upon a click

Currently, I have implemented a countdown timer using the provided code snippet. To prevent the count from resetting upon page refresh or reload, I am utilizing local storage. However, if there is an alternative solution to achieve this functionality, I wo ...

Using double quotes when adding HTML5 local storage entries

Currently, I am setting the value of a field to a variable like this: newUser = document.getElementById('userName').value; Then putting that variable into local storage: localStorage.setItem('userName', JSON.stringify(newUser)); Fet ...

Switching my Bootstrap navbar to a Right-to-Left layout

Currently working on creating a navbar that needs to go from Right to Left for Hebrew language compatibility. Experimenting with a responsive navbar layout where the linked buttons align on the Left and move towards the Right. Want to have the brand logo ...

Arrange the DIVs in the identical spot and switch them back and forth

I'm struggling with a dilemma involving two DIVs. I am looking to have two DIVs positioned in the exact same spot on the page and toggle between them. When one div disappears, the other should appear using jQuery toggle(). The challenge lies in havi ...

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

The CSS float is positioned beneath the Bootstrap navigation bar

Having an issue with the menu bars in my Rails 4 app. Specifically, I'm struggling with two divs overlapping. The goal is to align the "Register" and "Log In" blocks with the left-hand side menu while floating right. It should not float slightly belo ...

Using a scrapy spider to navigate through microsoft.com in search of the sign-in link

I have encountered an issue while trying to locate the sign-in link using a scrapy crawler on various websites, such as www.microsoft.com. Initially, the response I receive from the website does not contain the sign-in link. However, upon inspecting the "V ...

"Is there a way to verify the existence of checkbox array values within a database using PHP Laravel

In order to display checkboxes for each country that exists in the database, I need to verify if the countries in the database match with those in the list. Since the values are retrieved directly from the database and can't be set as input values due ...