Alternate solution for outdated browsers that stretches to the maximum height available

Is there a way to ensure equal height for all children using flexbox, but also have a fallback option for browsers like IE10 and similar?

I tried using display: table and display: table-cell, but it doesn't seem to work well with fixed heights. Additionally, table-layout: fixed only sizes based on the first cell's height if it is the largest.

html {
  box-sizing: border-box;
}

*,
:after,
:before {
  box-sizing: inherit;
}

.wrap {
  padding-left: 16px;
  padding-right: 16px;
}

.gel-layout {
  list-style: none;
  direction: ltr;
  text-align: left;
  margin-right: 0;
  margin-left: -8px;
  padding-right: 0;
  padding-left: 0;
}

.gel-layout--equal {
  display: table;
  table-layout: fixed;
  width: 100%;
}

.gel-1\/3 {
  width: 33.33333333%!important;
}

.gel-layout__item {
  width: 100%;
  display: inline-block;
  padding-left: 8px;
  text-align: left;
  vertical-align: top;
}

.gel-layout--equal>.gel-layout__item {
  display: table-cell;
}

.gel-c-grid-demo-item {
  width: 100%;
  padding: 8px;
  background-color: #d4e7eb;
  color: #121212;
}

.gel-c-grid-demo-item--auto {
  height: auto;
}

.gel-c-grid-demo-item--fill {
  background: repeating-linear-gradient(180deg, #d4e7eb, #d4e7eb 8px, #aec4cc 0, #aec4cc 16px);
}

.gel-c-grid-demo-item--first {
  height: 72px;
}

.gel-c-grid-demo-item--large {
  height: 144px;
}
<div class="wrap">
  <div>
    <h2>Equal Height</h2>
    <div class="gel-layout gel-layout--equal">
      <div class="gel-layout__item gel-1/3 left">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--auto gel-c-grid-demo-item--fill gel-c-grid-demo-item gel-c-grid-demo-item--first">one</div>
      </div>
      <div class="gel-layout__item gel-1/3">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--fill">two</div>
      </div>
      <div class="gel-layout__item gel-1/3">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--large gel-c-grid-demo-item--fill">three</div>
      </div>
    </div>
  </div>
</div>

Answer №1

A solution was found for the height issue by commenting the height and adding a hack with height:1px. Additionally, display:inline-table; was included for inner children to address the problem in Firefox mentioned by @Stickers

html {
  box-sizing: border-box;
}

*,
:after,
:before {
  box-sizing: inherit;
}

.wrap {
  padding-left: 16px;
  padding-right: 16px;
}

.gel-layout {
  list-style: none;
  direction: ltr;
  text-align: left;
  margin-right: 0;
  margin-left: -8px;
  padding-right: 0;
  padding-left: 0;
}

.gel-layout--equal {
  display: table;
  table-layout: fixed;
  width: 100%;
  height:1px; /* a hack to set the height of the children equal */
}

.gel-1\/3 {
  width: 33.33333333%!important;
}

.gel-layout__item {
  width: 100%;
  display: inline-block;
  padding-left: 8px;
  text-align: left;
  vertical-align: top;
}

.gel-layout--equal>.gel-layout__item {
  display: table-cell;
}

.gel-c-grid-demo-item {
  width: 100%;
  padding: 8px;
  background-color: #d4e7eb;
  color: #121212;
  height: 100%; /* added this height to make the height equal to the greatest element */
  display: inline-table; /* to fix firefox issue */
}

.gel-c-grid-demo-item--auto {
  /*height: auto; commented this height */
}

.gel-c-grid-demo-item--fill {
  background: repeating-linear-gradient(180deg, #d4e7eb, #d4e7eb 8px, #aec4cc 0, #aec4cc 16px);
}

.gel-c-grid-demo-item--first {
  /*height: 72px; commented this height*/
}

.gel-c-grid-demo-item--large {
  height: 144px;
}
<html>

<body>
  <div class="wrap">
    <div>
      <h2>Equal Height</h2>
      <div class="gel-layout gel-layout--equal">
        <div class="gel-layout__item gel-1/3 left">
          <div class="gel-c-grid-demo-item gel-c-grid-demo-item--auto gel-c-grid-demo-item--fill gel-c-grid-demo-item gel-c-grid-demo-item--first">one</div>
        </div>
        <div class="gel-layout__item gel-1/3">
          <div class="gel-c-grid-demo-item gel-c-grid-demo-item--fill">two</div>
        </div>
        <div class="gel-layout__item gel-1/3">
          <div class="gel-c-grid-demo-item gel-c-grid-demo-item--large gel-c-grid-demo-item--fill">three</div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

Here is another version with large content

html {
  box-sizing: border-box;
}

*,
:after,
:before {
  box-sizing: inherit;
}

.wrap {
  padding-left: 16px;
  padding-right: 16px;
}

.gel-layout {
  list-style: none;
  direction: ltr;
  text-align: left;
  margin-right: 0;
  margin-left: -8px;
  padding-right: 0;
  padding-left: 0;
}

.gel-layout--equal {
  display: table;
  table-layout: fixed;
  width: 100%;
  height:1px; /* a hack to set the height of the children equal */
}

.gel-1\/3 {
  width: 33.33333333%!important;
}

.gel-layout__item {
  width: 100%;
  display: inline-block;
  padding-left: 8px;
  text-align: left;
  vertical-align: top;
}

.gel-layout--equal>.gel-layout__item {
  display: table-cell;
}

.gel-c-grid-demo-item {
  width: 100%;
  padding: 8px;
  background-color: #d4e7eb;
  color: #121212;
  height: 100%; /* added this height to make the height equal to the greatest element */
  display: inline-table; /* to fix firefox issue */
}

.gel-c-grid-demo-item--auto {
  /*height: auto; commented this height */
}

.gel-c-grid-demo-item--fill {
  background: repeating-linear-gradient(180deg, #d4e7eb, #d4e7eb 8px, #aec4cc 0, #aec4cc 16px);
}

.gel-c-grid-demo-item--first {
  /*height: 72px; commented this height*/
}

.gel-c-grid-demo-item--large {
  /*height: 144px;*/
}
<div class="wrap">
  <div>
    <h2>Equal Height</h2>
    <div class="gel-layout gel-layout--equal">
      <div class="gel-layout__item gel-1/3 left">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--auto gel-c-grid-demo-item--fill gel-c-grid-demo-item gel-c-grid-demo-item--first">one</div>
      </div>
      <div class="gel-layout__item gel-1/3">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--fill">two</div>
      </div>
      <div class="gel-layout__item gel-1/3">
        <div class="gel-c-grid-demo-item gel-c-grid-demo-item--large gel-c-grid-demo-item--fill">three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>three
          <br>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №2

  • Reorganized the classes by removing the .item div and consolidating all classes. The parent element must have display:table or display:table-row for table behavior to work properly, such as equal heights.

  • Added border-spacing to the display:table element. Margins are ignored by table components, so setting border-spacing was necessary to separate and define each cell as its own entity.

  • Eliminated the .gel-1/3 class, which, although valid, was redundant as the cells were already set to be 33.33% under display:table-cell with display:table and table-layout.

  • During the class consolidation process, special attention was paid to removing double-hyphen classes -- as they are typically reserved for CSS variables and are not always considered safe.

Demo

html {
  box-sizing: border-box;
}

*,
:after,
:before {
  box-sizing: inherit;
}

.wrap {
  padding-left: 16px;
  padding-right: 16px;
}

.table {
  display: table;
  table-layout: fixed;
  border-spacing: 5px;
  width: 100%;
}

.cell {
  text-align: left;
  vertical-align: top;
  display: table-cell;
  padding: 8px;
  background-color: #d4e7eb;
  color: #121212;
  /*outline:2px solid red;*/
  background: repeating-linear-gradient(180deg, #d4e7eb, #d4e7eb 8px, #aec4cc 0, #aec4cc 16px);
}

.first {
  height: 72px;
}

.large {
  height: 144px;
}
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<style>

</style>
</head>
  <body>
    <div class="wrap">
  
        <h2>Equal Height</h2>
        <div class="table">

            <div class="cell first">one</div>

            <div class="cell">two</div>

            <div class="cell large">three</div>
 
        </div>
      </div>
    
  </body>

</html>

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

Blur effect on backdrop-filter causing shadowy inset borders (specific to Chrome and Windows)

Note: The issue mentioned below has been resolved in the latest version of Chrome (119.0.6045.200). While transitioning on backdrop-filter, I have observed a dark inset shadow that is only visible during the transition. This behavior seems to occur only ...

How can I link two separate webpages upon submitting a form with a single click?

Here is a snippet of my code: <form action="register.php" method="post"> <input type="text" name="uname"> <input type="submit" > </form> Within the register.php file, there are codes for connecting to a database. I am looking ...

Creating a clickable link that dynamically updates based on the span and id values, and opens in a new browser tab

I am attempting to create a clickable URL that opens in a new window. The URL is being displayed and updated on my HTML page in the following manner: Python Code: def data_cb(): return jsonify(waiting=await_take_pic()) Javascript Code: jQuery(d ...

javascript popup appears twice in IE when using PHP

After testing this script on multiple browsers, an issue arises when using IE. In all other browsers, the form submission alert only appears once. However, in Internet Explorer, the alert pops up twice. What could be causing this discrepancy? <!DOCTYP ...

"Hover over the image to see it enlarge and reveal text displayed on top using CSS3

I have been working on creating a responsive image page for my website. I've managed to make the images responsive and centered, no matter the size of the browser window. However, I encountered an issue where when I hover over an image, it enlarges a ...

Pass the variable to another page (Deliver a message)

If the registration and login pages are completed, is it possible to pass a variable from the registration page to the login page? I aim to notify the user that the account has been successfully created. The notification should appear similar to this: Che ...

Struggling with implementing a materialize modal?

I am encountering a problem with Materialize. This time, I am trying to create a modal div, but it doesn't seem to be working. The button is created, but when I click on it, nothing happens. I have made sure to link all the necessary Materialize files ...

Activate event in jQuery when clicking on a blank area, away from any div element

I need help figuring out how to hide a div when empty space on the margins of the page is clicked, as opposed to just any area outside of the div. I've managed to achieve this functionality when certain other divs are clicked, but I'm stuck on im ...

What are the steps to incorporating the League Gothic font into my website design?

Is there a way to incorporate League Gothic font into my website design? Visit the League Gothic GitHub repository Appreciate any guidance on this matter, ...

What are some ways to ensure a JQM-created button is clickable in Firefox?

I am working on making a div clickable in a jQuery Mobile powered website. The current code I have functions properly in Chrome and Safari, however, it does not work in Firefox - both on desktop and Android FF. <button data-icon="eye"> <a href ...

Create a basic grid layout using Bootstrap

I'm struggling to create this straightforward grid layout using Bootstrap: https://i.sstatic.net/fnQRt.png Essentially, I attempted the following method based on Bootstrap documentation: <td> <div class="row"> <div class=&q ...

Issue with data binding in file upload field

I am currently working on a project using Asp.Net Core MVC. In the model, there is a property called IFormFile. While using a basic input tag, everything works perfectly fine. However, when I tried to implement the file input plugin from this URL, the mode ...

Is the 404 error a result of the ajax code?

I'm currently working on a form that utilizes AJAX to validate and interconnect various form elements. Below is a simplified version of my code: <?php if( isset( $_POST['create_transaction'] ) ) { // do something } ?> <div> ...

"Shopping just got easier with our new drag and drop feature! Simply drag items

I want to develop a Virtual Shopping Cart system. Items will be retrieved from a database. A virtual basket will be available. Users can drag items and drop them into the basket, similar to shopping in a mall. Once the user clicks the save button, the s ...

Menu Design Inspired by Amazon Using jQuery

Can someone please assist me in locating a jQuery Amazon-style menu example? I would like to implement something similar and am hoping to avoid having to write it from scratch. Thank you! ...

Position the spinner in the center of the user's screen

I created my own spinner: '''' #spinner-bg-loading{ position: absolute; left: 50%; top: 25%; width: 80px; height: 80px; margin: -75px 0 0 -75px; border: 16px solid #FFFFFF; border-radius: 50%; border-top: 16px solid #1 ...

Issue with Vue's v-autocomplete component not clearing the user's typed text when an item is selected from

I have implemented a vue v-autocomplete component on my page. I am unsure if the current behavior is as expected, as I cannot find similar examples demonstrating this functionality. The issue arises when a user begins typing in text and the autocomplete ...

Gallery tiled with images enclosed in <a> tags

I've been experimenting with pure CSS (Bootstrap 4) to create a tiled gallery layout. To achieve this, I've been utilizing the flexbox capabilities provided by Bootstrap through classes like d-flex and flex-wrap. While everything seems to be wor ...

React Sticky sidebar implementation throughout the various components

My goal is to implement a sticky sidebar that moves smoothly across specific components on my webpage. The challenge I am facing is that the CSS 'sticky' property only allows movement within the component it was created in. So, my question is - w ...

Executing HTTP requests in ngrx-effects

I'm currently working on an Angular REST application using ngrx/effects and referencing the example application available on GIT. I am facing challenges while trying to replace hardcoded JSON data in effects with data from an HTTP REST endpoint. The e ...