Creating columns of equal height using Bootstrap 3 and flexbox

Working with Bootstrap 3 (unable to switch to Bootstrap 4) and looking to achieve the same-height columns effect as shown in the image: https://i.sstatic.net/WR55a.jpg Managed to get it done using position absolute and @media screen for image size and padding adjustments, but I believe there's a more efficient solution.

Discovered functional code here, but adding an image at the top disrupts the design - the picture ends up in an extra column stretching all content (here). Using display:block brings back the original issue of varying column heights.

Certain that there is a clean and clever way to solve this!

EDIT: Currently have a main row (green frame in the image below) with 3 columns. What if we create 3 rows instead (red frames) and apply equal height only to the middle content? Would work on larger screens, but on smaller screens where each column takes full width, it would result in 3 pictures stacked vertically, along with descriptions and buttons - not ideal! Is there a way to rearrange the column display for such cases to have 3x picture-description-button?

https://i.sstatic.net/k4BSy.jpg

edit2: snippet added

html,body {
height:100%;
}
      
.row-flex, .row-flex > div[class*='col-'] {  
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    flex:1 1 auto;
}

.row-flex-wrap {
-webkit-flex-flow: row wrap;
    align-content: flex-start;
    flex:0;
}

.container-flex > div[class*='col-'] div,.row-flex > div[class*='col-'] div {
width:100%;
}
<header>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</header>
<body>
<div class="container"><h3>.row-flex (make columns equal heights in each row)</h3></div>
<div class="container">
  <div class="row row-flex row-flex-wrap">
<div class="col-xs-4">
      <div class="well"> 
        Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, 
        totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae 
        dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.
      </div>
    </div>
    <div class="col-xs-4">
<img class="img-responsive" src="http://placehold.it/200x100">
    <div class="well"> 
        Duis pharetra varius quam sit amet vulputate.  
      </div>
    </div>
    <div class="col-xs-4">
    <div class="well"> 
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pharetra varius quam sit amet vulputate. 
        Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Aenean sit amet felis 
        dolor, in sagittis nisi. 
      </div>


  </div><!--/row-->
</div><!--/container-->
<hr>



</body>

Answer №1

To make the layout more flexible, try extending the use of flexbox to the children elements as well.

Keep in mind that images may not react well when directly inside a flex container. Wrapping the image in a div can help resolve this issue.

html,
body {
  height: 100%;
}
.row-flex {
  display: flex; /* columns are now equal height */
}
.col-md-3 {
  background: pink;
  display: flex;
  flex-direction: column;
}
.panel,
.well { /* make panels & wells expand to full height */
  flex: 1;
  display: flex;
  flex-direction: column;
}
.panel-footer { /* push footer to bottom */
  margin-top: auto;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
  <div class="row row-flex">
    <div class="col-md-3">
      <div class="panel panel-default flex-col">
        <div class="panel-heading">Title flex-col</div>
        <div class="panel-body flex-grow">Content here -- div with .flex-grow</div>
        <div class="panel-footer">Footer</div>
      </div>
    </div>

    <div class="col-md-3">
      <div>
        <img class="img-responsive" src="http://placehold.it/400x100">
      </div>
      <div class="well">
        Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
        sit aspernatur aut odit aut fugit.
      </div>
    </div>
    <div class="col-md-3">
      <div class="well">
        Duis pharetra varius quam sit amet vulputate.
      </div>
    </div>
    <div class="col-md-3">
      <div class="well">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pharetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Aenean sit amet felis dolor, in sagittis nisi.
      </div>
    </div>

  </div>
  <!--/row-->
</div>
<!--/container-->

Codepen Demo

Answer №2

One approach to achieving equal heights in CSS is by using dynamic methods, without specifying a fixed height.

Simply changing the display property from flex to block will not produce the desired result.

An alternative solution involves utilizing Javascript to determine the heights of three flex children and comparing them using Math.max(). The resulting value can then be applied to the flex children.

* {
  margin: 0;
  padding: 0;
}

.flex {
  display: flex;
  justify-content: space-between;
}

.flex-children {
  width: 30%;
  background: red;
}
<div class="flex">
  <div class="flex-children">asd</div>
  <div class="flex-children">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora et nisi harum eaque quas similique esse voluptas? Expedita in vitae, vel unde deleniti hic dolores rerum. Aliquam quos quidem quae.</p>
  </div>
  <div class="flex-children">ddey</div>
</div>

To ensure uniformity in height, consider overriding bootstrap styles specifically for the content being displayed.

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 adding additional columns to the final data output

When retrieving data from the database and binding it to a table, I found that I wanted to include additional columns in the displayed data. While I am getting the name value from the database, I also want to add a city column to the table on the UI. View ...

Font discrepancies in HTML field types "text" and "textarea" are causing inconsistent font display

Why do the text in my "text" and "textarea" fields show different fonts on my pages' HTML? I attempted to specify the font type in both the background CSS file and within the HTML, but it did not resolve the issue. Just to be transparent...I'm ...

How can I display data saved from step 2 in a multi-step form with 4 steps, when I return from step 3 to step 2?

Let's consider this scenario: Imagine the user is at step 2 and types their name into <input type="text" class="form-control input-xl" ngModel name="firstName"> They proceed to step 3 but then decide to return to step 2. The information entere ...

Concealing two div elements based on string content

I am working on a unique Wordpress blog post layout that showcases personnel profile cards, displaying 12 individuals at a time. Depending on whether or not a person has a Twitter handle entered in the backend, certain elements should either be shown or hi ...

Tips on how to select only the currently active tab and change its background color

I am currently troubleshooting the AJAX tabs functionality on my website. The issue I am facing is that the current code does not apply any styling to indicate an active tab. I believe I may need to use some JavaScript code to address this problem, but I ...

Focusing on the final (but not ultimate) elements within a specified tag

I am facing a challenge with an HTML structure containing multiple instances of a certain element along with two p elements beneath each: <some_tag></some_tag> <p></p> <p></p> <some_tag></some_tag> <p> ...

Concealing the text input cursor (caret) from peeking through overlaid elements on Internet Explorer

Currently, I am facing an issue with a form that includes a unique widget. This particular widget automatically populates a text input when it is in focus. The problem arises when the widget appears above the text input as intended. In Internet Explorer ...

What are some possible applications for leveraging the HTML5 <link rel> attribute duo of stylesheet and next?

The specification for HTML5 emphasizes the handling of each link created within a link element as separate entities. This means that multiple link elements with `rel="stylesheet"` are treated independently, considering them as distinct external resources a ...

Displacement occurs when the input tag is eliminated

After some trial and error, I have discovered that removing the input tag from the label causes a change in the layout height. I am puzzled as to why this is happening. Could there be a special reason for this height alignment issue when an input tag is pl ...

What should be displayed if there are no search results?

My form for filtering a database is working perfectly in the first section: $result=$dbh->prepare("SELECT * FROM performers WHERE accent='$txt_accent' AND hair='$txt_hair' AND gender='$txt_gender' AND location='$txt_l ...

Retrieve 2 data points from an HTML source code using Python

I'm struggling to extract data-b following the term "Grab" from the unmodified webpage code. There are multiple <tr> tags on the page and I need to specifically target those containing "Need" just before </a>. While I initially tried using ...

Tips for adjusting the CSS styles within a jQuery plugin

I need some help with styling the form on my test page located at While using FireBug, I noticed a lot of padding space surrounding the tabs within this div: <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom"> How can I redu ...

Tips for maintaining the webcam video in the center of the screen even when the height is set to 100% and the window is being resized

When using React, I encountered an issue with centering a webcam video while maintaining its height at 100% of the screen. Although the video fills the screen vertically correctly, adjusting the width of the window causes the video to lose its centered pos ...

"Usage of Wildcard in CSS Selectors for customizable path selection

When it comes to identifying elements using CSS selectors, I rely on a combination of path and attribute-based selectors for accurate results. For instance: div[attribute='test'] > div > div > div > span[attribute='test'] ...

Transform the text with a stylish touch within a 'textarea' element

I am currently working on a form with the following design: At the moment, I am at this particular stage and focusing on some minor details: One issue I have encountered is that the "Your text..." appears stuck to the top left corner of the textarea. I a ...

Encountering Error 500 with Jquery Min.Map File

ERROR: GET request to http://domain.com/assets/js/jquery-1.10.2.min.map returned a 500 Internal Server Error Can anyone help me figure out what's causing this error? I checked the log files in /var/log/error but couldn't find any information. T ...

Activate the child for an update

Welcome! I am a newcomer to Angular and would greatly appreciate any assistance. The parent component of my picker has the ability to create various rules for each option. However, these rules are dynamic and can change frequently. I need to ensure that ...

Instructions for downloading a file using Front End technology in Java and HTML

I am looking to initiate a file download upon clicking a button on the front-end interface. Front End <td><a name="${flow.name}" data-toggle="tooltip" title="Report" class="generateReport"><span class="far fa-file-excel"></span>&l ...

Having Trouble Loading PHP File with Jquery

I've been struggling with using JQuery/Ajax to load the content of my PHP file into a div tag. Below is the code snippet from my page that attempts to load the file: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/ ...

Scroll to the top of jQuery DataTables when clicking pages in a random order from the bottom to the top and

In my current project, I am working with jQuery Datatables and I need to customize its default behavior. Currently, when I navigate to page 61, the page scroll remains at the bottom of the page. However, if I then click on a lower page number like 60, th ...