So my logo doesn't go to the left properly in Safari browser only, I was wondering what's wrong with it
thanks
For the flex container always use prefixes (which you already do).
If you want to align logo to the left, simply add
flex-wrap: nowrap;
Another good practise with flexboxes for safari is always use flex property.
like so
-webkit-box-flex: 1 1 auto;
-moz-box-flex: 1 1 auto;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
P.S. This might be an good article to start with
the thing is if you use flex-direction: column; in Safari , you have to also mention flex-wrap: nowrap; otherwise it will add the width of each flex-item to it's parent container, thanks to Sergey for hinting that.
Related
What would be the best analogy for fr(fraction) unit in a flexbox layout? I was thinking of flex: 1 but not sure if it is the best match in terms of its growing/shrinking behavior.
What I'm trying to do is to make a fallback for grid layout so that it works in IE11. I have a grid statement grid-template-columns: 11.25rem 1fr; that I can't make work in IE (even with Auto-prefixer that adds -ms-grid-columns columns still stack on top of each other).
So I was thinking to maybe just implement it in flexbox for IE using something like this:
.container {
max-width: 46rem;
.parent {
display: flex;
& :first-child {
inline-size: 11.25rem;
}
& :last-child {
flex: 1;
}
}
}
Turned out flex: 1 works for my needs.
It's a shorthand for flex: 1 1 0px; so
flex-grow: 1 lets it grow when there is extra space.
flex-shrink: 1 lets it shrink when there is not enough space.
flex-basis: 0px allows it to have width defined by its content with respect to its container's width.
I have been unable to determine why flexbox is not working in IE 11.
For testing, I sourced a very simple flexbox layout from CodePen and have pasted the information below.
Chrome works as intended; IE11 fails.
Image of layout-success running on Chrome:
Image of layout-failure on IE11
body {
background: #333;
font-family: helvetica;
font-weight: bold;
font-size: 1.7rem;
}
ul {
list-style: none;
}
li {
background: hotpink;
height: 200px;
text-align: center;
border: 2px solid seashell;
color: seashell;
margin: 10px;
flex: auto;
min-width: 120px;
max-width: 180px;
}
.flex {
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
<ul class="flex">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
http://codepen.io/hankthewhale/pen/IdKkB?editors=110
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: 0
flex-shrink: 0
flex-basis: 35%
Make sure flex-shrink is enabled.
So instead of this: flex: 0 0 35%
Try this: flex: 0 1 35%
(In other cases flex-shrink needs to be disabled: Flex item overlaps another item in IE11)
Careful with percentage and unitless values with flex-basis
This may depend on your version of IE11. Behavior appears to vary.
Try these variations:
flex: 1 1 0
flex: 1 1 0px
flex: 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: 1 use flex: auto (or add in flex-basis: auto)
If you're using flex: 1 in flex-direction: row (such as on larger screens), and you switch to flex-direction: column in 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 the flex-basis value in the flex: 1 rule (which is usually 0, 0px or 0%, depending on the browser).
Using flex: auto should also work, which is short for:
flex-grow: 1
flex-shrink: 1
flex-basis: auto
Use old-fashion width / height properties instead of flex.
Use block layout instead of flex layout.
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: block instead of display: 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 display value 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;
}
For me, using
flex: 1 1 auto;
instead of
flex: 1;
solved the flex issue on IE 11.
Just use flex:1 0 auto;. It will work.
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: 0 1 (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.
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.
I have been unable to determine why flexbox is not working in IE 11.
For testing, I sourced a very simple flexbox layout from CodePen and have pasted the information below.
Chrome works as intended; IE11 fails.
Image of layout-success running on Chrome:
Image of layout-failure on IE11
body {
background: #333;
font-family: helvetica;
font-weight: bold;
font-size: 1.7rem;
}
ul {
list-style: none;
}
li {
background: hotpink;
height: 200px;
text-align: center;
border: 2px solid seashell;
color: seashell;
margin: 10px;
flex: auto;
min-width: 120px;
max-width: 180px;
}
.flex {
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
<ul class="flex">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
http://codepen.io/hankthewhale/pen/IdKkB?editors=110
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: 0
flex-shrink: 0
flex-basis: 35%
Make sure flex-shrink is enabled.
So instead of this: flex: 0 0 35%
Try this: flex: 0 1 35%
(In other cases flex-shrink needs to be disabled: Flex item overlaps another item in IE11)
Careful with percentage and unitless values with flex-basis
This may depend on your version of IE11. Behavior appears to vary.
Try these variations:
flex: 1 1 0
flex: 1 1 0px
flex: 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: 1 use flex: auto (or add in flex-basis: auto)
If you're using flex: 1 in flex-direction: row (such as on larger screens), and you switch to flex-direction: column in 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 the flex-basis value in the flex: 1 rule (which is usually 0, 0px or 0%, depending on the browser).
Using flex: auto should also work, which is short for:
flex-grow: 1
flex-shrink: 1
flex-basis: auto
Use old-fashion width / height properties instead of flex.
Use block layout instead of flex layout.
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: block instead of display: 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 display value 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;
}
For me, using
flex: 1 1 auto;
instead of
flex: 1;
solved the flex issue on IE 11.
Just use flex:1 0 auto;. It will work.
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: 0 1 (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.
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.
I have been unable to determine why flexbox is not working in IE 11.
For testing, I sourced a very simple flexbox layout from CodePen and have pasted the information below.
Chrome works as intended; IE11 fails.
Image of layout-success running on Chrome:
Image of layout-failure on IE11
body {
background: #333;
font-family: helvetica;
font-weight: bold;
font-size: 1.7rem;
}
ul {
list-style: none;
}
li {
background: hotpink;
height: 200px;
text-align: center;
border: 2px solid seashell;
color: seashell;
margin: 10px;
flex: auto;
min-width: 120px;
max-width: 180px;
}
.flex {
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
<ul class="flex">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
http://codepen.io/hankthewhale/pen/IdKkB?editors=110
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: 0
flex-shrink: 0
flex-basis: 35%
Make sure flex-shrink is enabled.
So instead of this: flex: 0 0 35%
Try this: flex: 0 1 35%
(In other cases flex-shrink needs to be disabled: Flex item overlaps another item in IE11)
Careful with percentage and unitless values with flex-basis
This may depend on your version of IE11. Behavior appears to vary.
Try these variations:
flex: 1 1 0
flex: 1 1 0px
flex: 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: 1 use flex: auto (or add in flex-basis: auto)
If you're using flex: 1 in flex-direction: row (such as on larger screens), and you switch to flex-direction: column in 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 the flex-basis value in the flex: 1 rule (which is usually 0, 0px or 0%, depending on the browser).
Using flex: auto should also work, which is short for:
flex-grow: 1
flex-shrink: 1
flex-basis: auto
Use old-fashion width / height properties instead of flex.
Use block layout instead of flex layout.
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: block instead of display: 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 display value 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;
}
For me, using
flex: 1 1 auto;
instead of
flex: 1;
solved the flex issue on IE 11.
Just use flex:1 0 auto;. It will work.
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: 0 1 (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.
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.
This question already has answers here:
Flexbox code working on all browsers except Safari. Why?
(3 answers)
Closed 5 years ago.
The chart below works on Chrome and Firefox, but Safari is shrinking the width of the boxes. This is also happening on mobile clients. I'm including the css for the chart container and a codepen to the complete markup and css.
https://codepen.io/juancho1/pen/akyNmp
#chart-container{
width: 100%;
height: auto;
border: 1px solid #39c3ec;
/*display: -webkit-box;*/
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
overflow-x: scroll !important;
}
I'm hoping someone has come across this specific issue before. While looking for a possible solution I saw that Safari has some issues with flexbox, and tried most of the solutions I've seen. It may be also related to the flex direction.
I'd appreciate any tips anyone may have!
Thanks
Update
As much as I love the upvotes I've been getting randomly, I've realized I made a pretty big mistake in my original post. The default flex value is 0 1 auto not 1 0 auto. However, this only adds to the reasoning behind why setting flex-shrink to 0 would keep flex items from shrinking, it just doesn't explain why they weren't shrinking in all browsers.
Original Post
I've ran into this issue before. On most other browsers, flex is automatically set to 1 0 auto, which is short for saying flex-grow: 1; flex-shrink: 0; flex-basis: auto;. flex-shrink: 0; should prevent the boxes from shrinking, but it seems safari does not automatically set this property. Simply set flex-shrink to 0 on your flex items and they will not shrink anymore.