So I have a flexbox with columns and max-height to make the columns stack next to each other in 3 columns.
This works fine in Chrome, but in Safari it seems to only use the last (rightmost) column to set the actual height of the container.
I've made an example here:
section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 400px;
padding: 10px;
border: 1px solid green;
}
div {
flex-basis: 100px;
width: 100px;
background-color: red;
margin: 10px;
}
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
Results in Chrome and Safari are screencapped below.
Chrome:
Safari:
This seems to be an obvious bug, but I can't find any information about it.
What I want to know is:
Safari versions 9 and up support the current flexbox spec without prefixes. Older Safari versions, however, require -webkit- prefixes. Sometimes min-width and max-width cause alignment problems which can be resolved with flex equivalents. See Flex items not stacking properly in Safari.
Getting the child of a flex-item to fill height 100%Set position: relative; on the parent of the child. Set position: absolute; on the child. You can then set width/height as required (100% in my sample).
By default, a flex container has the following width and height assigned. width: auto; height: auto; But you can set a fixed height and width to the flex container.
Fixed size If you remove the 100% width above, then the image should retain its normal size even when the available space is reduced. However, if you want to keep the 100% img for any reason, then you need to add the flex-shrink property to the element containing the image and give it a value of 0.
As stated in another answer about Safari problems with flexbox, because flex is relatively new (CSS3), not all browsers work as expected. In some browsers, flex layout is partially supported or fully botched, depending on the combination of properties you apply.
In this particular case, Safari simply refuses to acknowledge max-height: 400px
on the flex container. However, if the flex container isn't responding, you can get help from the parent.
This is where you are now:
section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 400px; /* not working in Safari */
width: 400px;
padding: 10px;
border: 1px solid green;
}
Try this instead:
body {
display: flex;
max-height: 400px;
}
section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
width: 400px;
padding: 10px;
border: 1px solid green;
}
body {
display: flex;
max-height: 400px;
}
section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
width: 400px;
padding: 10px;
border: 1px solid green;
}
div {
height: 100px;
width: 100px;
background-color: red;
margin: 10px;
}
<section>
<div></div>
<div></div>
<div></div>
<div style="height:200px"></div>
<div></div>
<div></div>
<div></div>
</section>
Another thing to keep in mind is that flex layout with column wrap
has many bugs. It's possibly the most bug-ridden area in flexbox today. Here are two more examples:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With