Flexbox columns with equal widths for Internet Explorer

I am currently working on a flexbox column layout that needs to be compatible with IE10. One issue I have encountered is that IE tends to expand a flex child based on its contents, while other browsers keep each flexbox at an equal width.

To address this problem, I have been setting a max-width: 50%, but it requires percentages to be adjusted depending on the number of columns needed. While this solution works for two columns, it becomes more complex when dealing with three or more columns, where we need values like 33.333%.

Does anyone know of an alternative method to ensure that IE10/11 maintains equal flex widths?

<div class="columns">
  <div class="column">
    <p>hey there this is some long text</p>
  </div>
  <div class="column"></div>
</div>


.columns {
  display: -ms-flexbox;
  -ms-flex-flow: row;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row;
  flex-flow: row;
  width: 100%;
}

.column {
  -ms-flex: 1 0 auto;
  -webkit-flex: 1 0 0;
  flex: 1 0 0;
  min-height: 200px;
  border: 1px solid red;
}

Link to Example Code

Answer №1

It has come to my attention that Internet Explorer will expand a flex child based on its contents, while other browsers maintain equal widths for each flexbox.

No, that is not entirely accurate; all browsers default to sizing the flex item according to its content.

There is a distinction, however, where in most browsers, a flex item's default flex value is flex: 0 1 auto, but in IE10 it is flex: 0 0 auto.

This essentially means that all browsers except IE10 allow flex items to shrink (the second value represents flex-shrink).

To achieve the desired outcome, all that should be necessary is flex: 1 1 0.

However, to ensure compatibility with IE 10 and 11, we must assign a unit to the flex-basis, such as 0px, and IE10 might also require width: 100%, although this cannot be confirmed as I am running an emulator.

Using the short notation flex: 1, IE11 generally sets its flex-basis automatically, whereas IE10 may not, and there may be uncertainties regarding the bug-free nature of the prefixed property; hence, employing the full shorthand *-flex would be safer since I lack devices with older browsers for proper testing.

Stack snippet

.columns {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  /*  "flex-flow: row" is default, as is "width: 100%"
  -ms-flex-flow: row;
  -webkit-flex-flow: row;
  flex-flow: row;
  width: 100%;*/
}

.column {
  -ms-flex: 1 1 0px;                  /*  IE10 fix  */
  -webkit-flex: 1 1 0;                /*  changed  */
  flex: 1;                            /*  changed  */
  min-height: 70px;
  border: 1px solid red;
  width: 100%;                        /*  IE10 might need this  */
}
<div class="columns">
  <div class="column">
    <p>hey there this is some long text</p>
  </div>
  <div class="column"></div>
</div>

<div class="columns">
  <div class="column">
    <p>hey there this is some long text</p>
  </div>
  <div class="column"></div>
  <div class="column"></div>
</div>

<div class="columns">
  <div class="column">
    <p>hey there this is some long text</p>
  </div>
  <div class="column"></div>
  <div class="column"></div>
  <div class="column"></div>
</div>

Answer №2

Flexbox is currently causing issues for IE10/11 users, but there are workarounds available to address these problems. While I cannot personally test the solutions, you can visit the link below for resources that may help resolve your issue.

http://caniuse.com/#search=flex

It's important to note the Known Issues page provided in the link above. Despite CanIUse indicating that flex works for IE11, many of its components are still malfunctioning.

If you're working with an odd number of columns like 3 and using 33% width, consider adding:

justify-content: space-between

or alternatively,

justify-content: space-around;

To properly space out the columns. For more details on justify-content, this resource offers additional information: https://css-tricks.com/almanac/properties/j/justify-content/

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

Creating a text design that spans two lines using Scalable Vector Graphics (SVG

I am working with an SVG that displays strings pulled from an Array... {"label":"Here is an example of the string...", "value":4}, The text above is shown in an SVG element as... <text>Here is an example of the string...<text> I would like ...

Causing a singular object to drift towards the right

Despite its simplicity, I have been struggling to position one of the items on the right side. Currently, I have multiple items and I am trying to get the 'Logout' button to stick to the right. body { margin: 0; background: #222; font-fa ...

Placing pictures one on top of the other as shown in the illustrations

Just joined this community and hoping for some guidance. I'm working on arranging separate images in a specific layout like this. Here's my code on jsfiddle. This is the HTML I'm using: <body> <div class="grid-container" ...

String representation of opacity value shown instead of numerical value

I recently implemented an opacity slider using React hooks in my project. Here is a snippet of the code: https://i.sstatic.net/m0JtM.png Within my table, I set the opacity like this: <td> <img src="link" opacity={data.socialOpaci ...

What is the best method to shift the middle div to the top of the CSS layout?

My goal is to create a responsive web page with three divs arranged in one column for small screens and two columns for larger ones. However, the layout doesn't look quite right unless the middle div is moved to the top like this: https://i.sstatic.n ...

Animate owlCarousel slide motion in reverse when using the Prev and Next buttons

The default functionality of owlCarousel is to move to the right when clicking Next and to the left when clicking Prev. However, after applying animations, both directions always move in the same direction. Check out this sample on jsfiddle to see the iss ...

Sass encountered an issue when trying to import using the "~" symbol from the node_modules directory

I am currently developing a single-page web application using Angular 6, and I recently integrated the ngx-toast library into my project. However, I encountered an issue when trying to load the libraries by adding the following Sass code with the "~" symb ...

Height Difference Caused by Textarea Overflow with Auto Scrollbars

Displayed below is code that generates a textarea with 3 visible rows: <textarea id="txtInput" rows="3" cols="20" style="overflow:auto"></textarea> Unexpectedly, in Firefox (version 20.0.1), the textarea displays 4 rows instead of 3. To view ...

Transforming the text to be "unreadable"

I find myself in a rather odd predicament where I must display my name and contact details on a webpage. Although I am comfortable with sharing this information, I would prefer that it remain unreadable to robots or other unauthorized sources. Essentially ...

Creating a tournament bracket in HTML using a table structure

For the past 3 weeks, I've been grappling with a problem that has me stumped. I just can't seem to figure it out for the life of me. What I'm attempting to achieve is a specific output or presentation using tables. Here's an example of ...

The Bootstrap 4 accordion won't stay closed and keeps popping open when I try to close

Having an issue with the example accordion from Bootstrap 4's documentation. After troubleshooting, I discovered that the 'show' class gets removed and added again when trying to close the card. Links to images: https://i.sstatic.net/lxKiK. ...

Is there a way to duplicate a specific quantity of icons with Polymer?

I am facing a bit of a challenge with a seemingly simple task. My goal is to showcase the number of credits completed by each student in my list using star icons. For instance, John ★, Sarah ★★, Ken ★, and Jared ★★★★. The JSON data contai ...

Issue with fortawesome icon: relative and absolute positioning not functioning as expected

I have utilized a diamond symbol from the Fort Awesome icon collection and noticed that when I target the i tag in my CSS, the icon becomes highlighted (see screenshot attached). However, I am encountering issues with relative and absolute positioning not ...

Conceal the PayPal Button

Currently, I'm facing a challenge where I need to dynamically show or hide a PayPal button based on the status of my switch. The issue is that once the PayPal button is displayed, it remains visible even if the switch is toggled back to credit card pa ...

CSS fixed positioning involves positioning an element relative to the

My website includes a div positioned below the header that contains quick links. I have implemented the solution from http://davidwalsh.name/persistent-header-opacity to ensure this div remains on-screen at all times. However, I would like it to appear a ...

Dropdown menu remains unable to open

One of the dropdown menus on my website is not retracting back properly, but only on the contact page where a Google map is displayed. The issue looks like this: I've tried tweaking the CSS code without success. What could I be missing? Should I prov ...

What are some strategies for keeping the focus state on the parent item in a dropdown menu?

When I interact with the dropdown menu in my navigation bar, the color changes for the child items. How can I make sure that the parent item maintains the same colored background even after clicking elsewhere on the page? To better understand the issue, i ...

Unable to execute a basic opacity transition on a div element

Why isn't the opacity transitioning in Chrome? I only want it to fade in with the 'transitions' class without fading out first. Check out this code sample: http://jsfiddle.net/chovy/t37k3/9/ <div></div> <a href="#" class="s ...

Ways to modify the border style of a checkbox using CSS

Is there a way to modify the border style of a checkbox input? I tried using border:1px solid #1e5180, but it doesn't seem to work in FireFox 3.5! ...

CSS: Adjusting color when hovering

I've been working on a website featuring clickable images, but I'm struggling with the ...:hover function. My goal is to have the image overlayed with a white color at 0.1 opacity upon hovering. <html> <head> <style> ...