Creating flexbox items with equal height

I have a flexbox parent with flex-direction set to row. Within this parent, I have two children that I want to have the same height!

Both of these children contain dynamic content with varying heights.

The issue I'm facing is that when I add text to the right child, the left one grows in height. But if the left child grows, the right one remains small.

Shouldn't they both behave the same way?

Here is a fiddle for reference: https://jsfiddle.net/4g6uevok/8/

HTML:

<div id="main">
  <div class="left">
    <div class="title">MY TITLE:</div>
    <div class="left-area">

      <div class="left-area-row">
        <div class="left-area-row-titulo">#1</div>
        <div class="left-area-row-info">A</div>
      </div>
      <div class="left-area-row">
        <div class="left-area-row-titulo">#2</div>
        <div class="left-area-row-info">B</div>
      </div>
      <div class="left-area-row">
        <div class="left-area-row-titulo">#3</div>
        <div class="left-area-row-info">AC</div>
      </div>

    </div>
  </div>

  <div class="right">
    <div class="title">SECOND TITLE:</div>
  </div>
</div>

CSS:

#main {
    width: 100%;
    height:auto;
    margin-top: 30px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: stretch;
    background-color: red;
}

.left{
    width: 400px;
    display: flex;
    flex-direction: column;     
    background:lime;
    align-items: stretch;
}

.title {
    width: 100%;
    font-size: 1.5em;
    color:#525252;
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    font-weight: bold;
    font-family: "emir-bold";
}

.left-area {
    width: 100%;
    display: flex;
    flex-direction: column;
}
.left-area-row {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}
.left-area-row-titulo {
    width: 49.5%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background-color: #819196;
    color: white;
    padding: 6px;
    margin:0 2px 4px 0;
}
.left-area-row-info {
    width: 49.5%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #CCCCCC;
    padding: 6px;
    margin:0 0 4px 2px;
}

.right {
    width: calc(100% - 430px);
    height: 100%;
    display: flex;
    flex-direction: column;
    background:orange;
    align-items: stretch;
}

Answer №1

By default, flex items are aligned to `stretch`. The `height:100%` value in the `.right` class is preventing it from taking up the entire height. Try removing `height:100%` from the `.right` element.

#main {
  width: 100%;
  height: auto;
  margin-top: 30px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: stretch;
  background-color: red;
}

.left {
  width: 400px;
  display: flex;
  flex-direction: column;
  background: lime;
  align-items: stretch;
}

.title {
  width: 100%;
  font-size: 1.5em;
  color: #525252;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  font-weight: bold;
  font-family: "emir-bold";
}

.left-area {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.left-area-row {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.left-area-row-titulo {
  width: 49.5%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background-color: #819196;
  color: white;
  padding: 6px;
  margin: 0 2px 4px 0;
}

.left-area-row-info {
  width: 49.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #CCCCCC;
  padding: 6px;
  margin: 0 0 4px 2px;
}

.right {
  width: calc(100% - 430px);
  display: flex;
  flex-direction: column;
  background: orange;
  align-items: stretch;
}
<div id="main">
  <div class="left">
    <div class="title">MY TITLE:</div>
    <div class="left-area">
      <div class="left-area-row">
        <div class="left-area-row-titulo">
          #1
        </div>
        <div class="left-area-row-info">A</div>
      </div>
      <div class="left-area-row">
        <div class="left-area-row-titulo">
          #2
        </div>
        <div class="left-area-row-info">BA</div>
      </div>
      <div class="left-area-row">
        <div class="left-area-row-titulo">
          #3
        </div>
        <div class="left-area-row-info">C</div>
      </div>
      <div class="left-area-row">
        <div class="left-area-row-titulo">
          #4
        </div>
        <div class="left-area-row-info">D</div>
      </div>
    </div>
  </div>
  <div class="right">
    <div class="title">SECOND TITLE:</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

Minimize the amount of space between two heading elements

Is there a way to decrease the distance between two heading tags? I want the h2 tag to be nearer to the h1 tag. Here is the CodeSandbox link for reference: https://codesandbox.io/s/rough-framework-tsk5b ...

Ensure that the following div remains positioned beneath the current one

After reading through this question on Stack Overflow, about creating a responsive table with both vertical and horizontal headers, I came across this particular issue, demonstrated in this codepen example: Currently, the second table appears directly bel ...

Using jQuery to highlight the navigation menu when a specific div scrolls into view

I have implemented a side navigation consisting of circular divs. Clicking on one scrolls you to the corresponding .block div, and everything functions correctly. However, I am now curious if it is feasible to highlight the relevant .nav-item div based on ...

What is the best way to assign a unique color to two overlapping cells in an HTML table using HTML and jQuery?

I have a task to highlight a row or column when a checkbox is selected, similar to the example shown in the image below. How can I adjust the code so that the overlapping cell gets a different color instead of green or yellow? For instance, in the image b ...

Issue with Collapse Feature on Bootstrap 3.x Navbar

The Bootstrap 3 Navbar expands properly in full screen and on a browser with a small width on a desktop PC and mobile browsers, but when using the Toggle navigation button, it doesn't slide down. I have tried to replicate the code from this example: h ...

I have a flex box with an image and text line inside. How can I adjust the width of the box and text to automatically match the size of the image?

Consider the code snippet below: <style> .img_box { display: flex; } </style> <div class=img_box> <img src=img/> <div>Title text of varying length. It may exceed the image's width or be smaller.</div> & ...

Tips on verifying if user x has sent over two messages in the chat and concealing their identity

I have a JavaScript chat application that is causing me some trouble. I recently implemented a feature to display user names on top of messages, and while it works well for the first message, I am struggling to hide the user's name when they send subs ...

How to make text transition between colors using CSS or jQuery

I'm looking to make a text blink with alternating colors: For instance: blinking a text with white, green, white, green, white, green I am open to either using jQuery or CSS. ...

The lobster custom font is malfunctioning in Internet Explorer

I am trying to use the unique font called lobster. After downloading the lobster.woff2 file, I stored it in the font folder. In my custom CSS, I added the following: @font-face { font-family: 'Lobster'; font-style: normal; font-weight: 40 ...

What is the best way to set up a dropdown menu in a data grid where the width matches the fields?

I am looking to optimize the layout for various screen resolutions and ensure compatibility with the latest versions of IE, Firefox, and Chrome. ...

dynamic text overlay on a bootstrap carousel

Having limited knowledge in html and css, I am using a bootstrap carousel slider with text. I am trying to change the color of the box randomly. https://i.sstatic.net/TozUP.jpg Here is the code that I am currently using: <ol class="carousel-indicato ...

Ensure that the bottom border of the nav-item is in line with the

Is there a way to make the bottom border of a bootstrap nav item align perfectly with the bottom border of the navbar? My goal is to use the bottom border as an indicator for the selected element. I managed to achieve this with the default height of the na ...

The CSS property for fixing an element in place: position

On my website, I have a position:fixed <div> that appears in the center of the screen. Whenever there are messages, a second position:fixed <div> is displayed next to the first one. I've noticed that on various screen sizes, like a netbo ...

Identify the current slide or div within a jQuery slideshow

I am currently facing an issue with my slide show that is composed of divs, each containing a picture and some html controls. The problem arises when clicking on a control in a slide other than the first one - it only updates the first slide. The only thin ...

Learn a valuable trick to activate CSS animation using a button - simply click on the button and watch the animation start over each time

I already know how to do this once. However, I would like the animation to restart or begin again when the user clicks on it a second time. Here is what I have: function animation() { document.getElementById('ExampleButton').className = &apo ...

What is the best way to create space between three columns in Bootstrap?

Despite my efforts to find a solution on Stackoverflow, I have not been able to locate exactly what I need. I am trying to evenly space and center three columns across my page. However, when I assign col-md-4 to each column, they end up too close together ...

Changing Ionic Column Widths Based on Content Length

In my dynamic ionic 2 grid system, I am facing a layout issue. <div> <ion-row> <ion-col > ; <ion-card-header class="card-header"> {{hunt.title}} </ion-card-header> </ion-col> <ion-col *ngIf="!hunt. ...

Insert an svg element into the content property

Is it possible to insert an SVG link within the content property? .selectedItem::before{ content: " any svg link "; ...

<container> rectangular form

.products { width: 100%; height: 500px; background: gray; } .box { width: 250px; height: 300px; background: darksalmon; border: 1px solid #000; } <div class="products"> <div class="box"> <p>Ola</p> </div> ...

When positioning 2 divs on top of each other, rotating one by 180 degrees causes it to be considered secondary in the visibility hierarchy. What is the reason behind this?

While delving into the realm of HTML, I stumbled upon a concept that has left me perplexed. Upon stacking two divs on top of each other, I observed an interesting phenomenon where rotating the second div by 180deg (i.e transform:rotateY(180deg)), causes t ...