Edit - the original answer was not entirely correct
The important aspects here are
- The flex element
div.imageContainer
needs a positive flex-shrink
value - The child element (
display:inline
) img
of the flex element requires its own restriction to ensure that it does not overflow the flex element. - According to the W3C flexbox spec * , the flex element requires a certain size limit, which we can satisfy by delcaring
min-width:1px
or max-width:100%
on .imageContainer
; otherwise, in accordance with the specification, the .imageContainer
must accept its content size, i.e. the full native size of the PNG image, equal to 1000px.
The OP question is already satisfied with point 2, but not with points 1 and 3. Here is the CSS that I used:
.mediaContainer { overflow: visible; width:100%; } .mediaCenterContainer { display: flex; } .imageContainer { flex-shrink:1; min-width:1px; } .imageContainer img { max-width:100%; }
... and here is a violin showing it.
Many thanks to @dma_k for pointing out the error in my original answer.
* I usually hate the W3C specs link, but this section is actually quite readable; I would recommend people read it.
Original answer
Firefox 36 (currently a preview of dev) gives the behavior that you would expect if you are restricting the div, not img. You can do this using flex-shrink
:
.imageContainer { flex-shrink:1; }
... or short flex
property:
.imageContainer { flex: 0 1 auto; }
... or using the max-width
declaration that you posted on img
, but also on the div
:
.imageContainer, .imageContainer img { max-width:100%; }
Thus, Firefox allows flexible elements to overflow their containers. I do not know the flexbox specification very well, but it seems natural that it will be so; therefore, the flex-shrink
property exists.
source share