Chrome method for creating Flexbox columns of equal height

I am implementing a simple 2-column layout and I want to utilize Flexbox to ensure equal heights for the columns:

HTML

<div class="row flex">
    <!-- menu -->
    <div class="col-xs-4">
        <aside>
            Menu content will be placed here
        </aside>    
    </div>
    <!-- content -->
    <div class="col-xs-8">
        <p>Content text goes here with some lorem ipsum...</p>
    </div>
</div>

CSS

body { color: red; }
.flex { display: flex; }
aside { background: #000; height: 100%; }

The layout works in Firefox but encounters issues in Chrome. You can view the Fiddle here.

I have attempted various solutions, including adding vendor prefixes, but the problem persists.

Answer №1

When using Flexbox to create two equal columns:

  • Set the parent container to display: flex

  • Create each column with a div and give them flex: 1 to grow or shrink

To make the child of the first column stretch:

  • Also apply display: flex to the first column so its children can have flex properties to grow

  • Assign flex: 1 to the aside child for it to grow or shrink

Here is a simple guide on Flexbox.

Flexbox Compatibility: Works on IE11+ and all modern browsers.

Example


Using Bootstrap: Check out this updated fiddle from your comment. The 1px left gap has been removed by using

div.flex.row:before, div.flex.row:after { display: none }

Related answer: How to remove 1px gap in Chrome when using display:flex


I have simplified unnecessary classes for this example. Currently, both columns have heights based on the tallest one. You could opt to fill the entire page height by adding height: 100vh to the flex container — learn more about viewport units here.

Viewport Units Compatibility: Viewport Units are widely supported.

To adjust a column's width, change its flex value. In this example, I set the second column to flex: 3 to make it wider.

body {
  color: red;
  margin: 0;
}
.flex {
  display: flex;
  /*To make columns span full height of page, use:
  height: 100vh;*/
}
.column {
  flex: 1;
}
.column:first-child {
  display: flex;
}
.column:last-of-type {
  background: #000;
  flex: 3;
}
aside {
  flex: 1;
  background: #F90;
}
<div class="flex">
  <!-- menu -->
  <div class="column">
    <aside>
      Menu content
    </aside>
  </div>
  <!-- content -->
  <div class="column">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ac elementum justo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus nec elementum erat. Suspendisse consequat ut metus ut cursus.
      Aenean et lectus id libero venenatis varius. Vivamus luctus ligula sit amet faucibus vulputate. Vestibulum tincidunt fringilla mauris, a vulputate magna egestas nec. Vivamus a odio ut nibh viverra fermentum.</p>
    <p>Nulla facilisi. Pellentesque nec libero leo. Duis porta ut neque vulputate blandit. In vel quam eu eros finibus feugiat ut in nulla. Morbi congue, tellus commodo euismod pulvinar, lacus dui fringilla lectus, in tempus mi nulla semper ex. Integer feugiat,
      lectus a facilisis rutrum, ex magna tincidunt ligula, in suscipit turpis lorem quis neque. Suspendisse dictum, nulla at aliquet cursus, magna tellus mattis purus, nec volutpat mauris nunc non neque. Mauris pretium mauris sed eros interdum lobortis.
      Aenean id vestibulum nisl. Praesent sit amet tempor nulla, consequat viverra ante. Maecenas eu pretium lacus, a consectetur sem. Proin viverra eget turpis eu condimentum. Donec et egestas enim. Maecenas fermentum auctor ligula, nec fringilla mi.
      Quisque hendrerit purus eget urna semper sodales.</p>

  </div>
</div>

Answer №2

My solution incorporates Modernizr and jQuery, along with the Equalize plugin.

Check out my implementation here: http://jsfiddle.net/0Leymgbe/1/

This is how it works in action:

if ($().equalize) { // ensure plugin is loaded
    $(window).on("resize", function () {
        (Modernizr.mq("(min-width: 768px)")) // if viewport is tablet or desktop size...
        ? $('.row').equalize({reset: true}) // equalize columns
        : $('.row > div').css({'height': 'auto'}); // reset to original height for smartphones
    }).resize(); // trigger resize on page load as well
}

When the window is resized (or on initial load), Modernizr determines if the viewport width exceeds 768px (tablet/desktop): if yes, jQuery equalizes columns; if not (smartphones), heights are restored to default.

Unfortunately, I couldn't find a straightforward way to achieve this using CSS3 flexbox alone.

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 incorporating tabs into a Rails 3 application with the help of Sass/Haml or CoffeeScript

Currently, I am looking to implement tabbed views in a project I am developing using Rails 3. To ensure compatibility with the latest features of Rails, I have decided to utilize Sass and CoffeeScript as my primary tools. If anyone has any resources or tu ...

Steps to create a thumbnail image following the insertion of an image into an input type="file" within a form, and subsequently submitting both elements on the form together

Currently, I am working on a form that enables users to upload images. Once the user submits the form, my goal is to create thumbnails for each image on the front-end and save them on the server afterwards. Due to security restrictions, changing the value ...

Tips for incorporating a download button into a video player using Plyr JS

I'm using Plyr JS and I am trying to add a download option for each video. Here is what I've done so far to make the download option work: Even though I have included: controlsList="nodownload" <video controls crossorigin playsinline contro ...

Can you explain the variance between a DIV using display: inline-block versus a SPAN element?

Can you explain the distinction between a DIV using display: inline-block and a SPAN? Furthermore, what sets apart a SPAN with display: block from a DIV? ...

Defining the active element in the menu using JavaScript

I need help with my navigation menu: <ul> <li id="active"><a href="/">Home</a></li> <li><a href="/about/">About Us</a></li> <li><a href="/services/">Our Services</a>< ...

Combine React 17 with webpack 5 and babel-plugin-react-css-modules, enabling the use of CSS modules with stylename functionality

I am in the process of setting up a new React application using the latest technologies available, including React 17, Webpack 5, and other essential modules. My goal is to implement CSS modules utilizing the styleName concept with the help of babel-plugi ...

Google API integration in Chrome Extension Manifest

I'm seeking advice on how to modify my chrome manifest for an extension in order to enable communication between Google API servers and the application. The application functions properly when accessed directly (not as an extension). However, when lo ...

To open a popup menu with a text box, simply click on the text box

Whenever the text box text is clicked, a popup menu should open with a text box. Similarly, when the filter icon in the right side corner is clicked, a menu should open with a list of checkboxes. However, currently both menus are opening when clicking on b ...

The origin of the distribution file diverges from the source path of the development

Currently, I have implemented a task runner with Gulp to export all my folders into a distribution folder. However, an issue arises when exporting images to the distribution folder as the path name differs from what is specified in my source files. For ins ...

What is the best way to increase padding in a Vuetify view element?

I have been attempting to increase the padding of my view by utilizing the "px-5" class on the container within the view. However, I am struggling to achieve the desired amount of padding. What I am aiming for is padding similar to what is shown in this sc ...

The code encountered an error because it was unable to access the property 'style' of an undefined element on line 13 of the script

Why is it not recognizing styles and showing an error? All paths seem correct, styles and scripts are connected, but it's either not reading them at all (styles) or displaying an error. Here is the html, javascript, css code. How can this error be fix ...

Validating HTML using EJS templates set as "text/template" elements

What is the general consensus on HTML validation when utilizing a framework such as Backbone or Meteor and generating views in the client from EJS templates? An issue arises with the fact that name is not considered an official attribute for a <script& ...

What is the process for embedding images and text within a nested division element?

I have a website layout with 4 main sections: header, left side, right side, and footer. I would like to further divide the header into two sections - left header and right header. The right header should contain an image along with other options like home ...

Personalizing a class specifically for error messages within the jQuery Validation plugin

When using the jQuery Validate plugin, is it possible to set a separate class for the error message element without affecting the input element's class? ...

Interacting with Cassandra using PHP

I am attempting to execute a SELECT query from the Cassandra Database using a PHP script. The connection is successfully established through PHP. Here is the query: $session = $cluster->connect($keyspace); $result = $session->execute("SELEC ...

Chrome on OSX Mavericks threw a RangeError because the maximum call stack size was exceeded

While attempting to run an Angular app using linemanjs in Chrome on a Mac, I encountered the following error: Uncaught RangeError: Maximum call stack size exceeded An interesting observation is that the site functions properly on Chrome on a Windows mach ...

"Clicking on the hamburger menu causes the webpage to reset its scroll

I recently integrated a mobile hamburger menu into my website, which is primarily built around a single page. However, I noticed that whenever I open the menu, it automatically scrolls to the top of the page regardless of where you were previously scrollin ...

Use CSS alignment to combine both the profile picture and title on a webpage

Is there a way to seamlessly integrate a profile picture with text (title) on my tumblr theme? My main challenge lies in getting the alignment right. Additionally, I want it to look good in responsive view. If the title becomes too long, it should wrap un ...

Having trouble accessing the templateUrl for HTML in Angular version 1.6

I am currently working on a basic Angular 1.6 web application. Although I have created a state for the URL "/", it seems that Angular is unable to locate the file for some reason. The folder structure looks like this: https://i.stack.imgur.com/2p6bP.png ...

Python code encountering issues within Django framework

I'm having trouble showing and hiding HTML elements based on the data I receive after clicking a button. The output of another Python file will generate this data, but the if statement doesn't seem to be working as expected: {% if data == 'e ...