Given a flex container
figure {
display: flex;
align-items: flex-start;
}
and a 300x300 image with its flex-basis set at half its intrinsic width:
figure img {
flex: 0 0 150px;
}
Chrome 41 and Safari 7 ignore the aspect ratio and display it as 150px x 300px:
Firefox 35 on the other hand keeps the intrinsic aspect ratio intact:
figure {
display: -webkit-box;
display: -moz-box;
display: box;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: start;
-moz-box-align: start;
box-align: start;
-webkit-align-items: flex-start;
-moz-align-items: flex-start;
-ms-align-items: flex-start;
-o-align-items: flex-start;
align-items: flex-start;
-ms-flex-align: start;
width: 100%;
border: 1px solid black;
}
figure img {
-webkit-box-flex: 0;
-moz-box-flex: 0;
box-flex: 0;
-webkit-flex: 0 0 150px;
-moz-flex: 0 0 150px;
-ms-flex: 0 0 150px;
flex: 0 0 150px;
}
figure figcaption {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1 1 auto;
-moz-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
}
<figure>
<img src="//placekitten.com/g/300/300" />
<figcaption>
I'm the caption
</figcaption>
</figure>
Who is correct? I believe the relevant section of the spec is Cross-size determination, but I'm having a hard time interpreting it.
In this example the flex-grow and flex-shrink properties are both set to 1 on all three items, indicating that the flex item can grow and shrink from the initial flex-basis. The demo then changes the flex-basis on the first item.
Note: If the element is not a flexible item, the flex-basis property has no effect. yes. Read about animatable Try it The numbers in the table specify the first browser version that fully supports the property.
The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise set with box-sizing. Note: in case both flex-basis (other than auto) and width (or height in case of flex-direction: column) are set for an element, flex-basis has priority.
It will then grow and shrink from that flex-basis. This means that, for example, when the flex-basis of the first item is 200px, it will start out at 200px but then shrink to fit the space available with the other items being at least min-content sized.
According the editors draft of the current Flexbox spec, neither of these browsers are rendering this correctly.
When I saw this question posted here, I asked about it on the www-style mailing list, and this is the discussion it prompted (via readable-email.org):
The consensus is that a strict interpretation of the current draft would suggest that the image be sized to 300x300 pixels because that's the minimum content size of the flex item and flex items are not supposed to shrink below their minimum content size if their min-size property is auto
(the default, and the case in your example).
Daniel Holbert (Flexbox implementor on Firefox) continued this discussion on another thread where he proposed that items with an intrinsic aspect ration should be allowed to shrink to below their minimum content size. He states:
min-content sizes aren't really a useful lower-bound for flex items with aspect ratios. These flex items can shrink (honoring their intrinsic aspect ratio) below their min-content size, without overflowing.
Anyway, as I said, the answer to your question is that neither browser is rendering this correctly (as per the current spec), but it's possible that the spec will change to handle this case and the way Firefox is currently rendering it will be considered correct in the future.
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