Flex Property Not Working In Ie
Solution 1:
IE has a problem parsing the flex property.
Here are a few workarounds that have worked for me:
Use the long-hand properties instead of the shorthand.
Instead of something like this:
flex: 0 0 35%.Try this:
flex-grow: 0flex-shrink: 0flex-basis: 35%
Make sure
flex-shrinkis enabled.So instead of this:
flex: 0 0 35%Try this:
flex: 0 1 35%(In other cases
flex-shrinkneeds to be disabled: Flex item overlaps another item in IE11)
Careful with percentage and unitless values with
flex-basisThis may depend on your version of IE11. Behavior appears to vary.
Try these variations:
flex: 1 1 0flex: 1 1 0pxflex: 1 1 0%
Beware! Certain css minifiers will replace 0px with 0, which can be a really annoying thing to debug (however, they won't change 0% for some reason).
More details here:
- Image behavior within flexbox (rows embedded in columns)
- Why does shorthand flex property behave differently than long hand properties in IE?
Instead of
flex: 1useflex: auto(or add inflex-basis: auto)If you're using
flex: 1inflex-direction: row(such as on larger screens), and you switch toflex-direction: columnin a media query (let's say for mobile devices), you may find that your flex items collapse.In your media query, add
flex-basis: auto. This will override theflex-basisvalue in theflex: 1rule (which is usually0,0pxor0%, depending on the browser).Using
flex: autoshould also work, which is short for:flex-grow: 1flex-shrink: 1flex-basis: auto
- Use old-fashion
width/heightproperties instead offlex.
Use
blocklayout instead offlexlayout.You don't need to completely abandon flex layout. But for a particular container you may be able to get the job done with
display: blockinstead ofdisplay: flex; flex-direction: column.For example, in needing to use the padding trick to responsively embed a video in a flex item, the obstacle I faced was that some browsers don't work well with percentage padding (or margin) in a flex container.
To make it work I switched the
displayvalue on the flex item from this:/* a flex item, also a nested flex container */#footer-container > article { display: flex; flex-direction: column; }to this:
#footer-container > article { display: block; }
Solution 2:
For me, using
flex: 11 auto;
instead of
flex: 1;
solved the flex issue on IE 11.
Solution 3:
Just use flex:1 0 auto;. It will work.
Solution 4:
As in @Michael_B answer, limit the growth with Flexbox flex property: flex: 0 1 (1/n - b) taken in % value, where n is the number of flex items in a row and b is the gap that you want to see between flex items in IE.
On the flex items along with flex property above use the max-width property with percentage value of 1/n - b.
In your case the generalized CSS for the flex item would be:
li {
// ... the remaining code from your snippet// Calculate the following manually and insert or use CSS preprocessor that does math for you.// See the formula explanation above.max-width: (your flex container max-width / 2) * 100% - b;
flex: 01 (your flex container max-width / 2) * 100% - b;
}
In actual case with 5 items / row there will be (1/5) * 100% - 1% = 19% => max-width: 19% and flex: 0 1 19%;.
Play with b parameter to make flex items short enough to allow flex: wrap; work.
Solution 5:
In my case, the CSS minifier rejects the px unit of the last argument in -ms-flex shorthand rule, I tried using % unit and it works fine.
Post a Comment for "Flex Property Not Working In Ie"