I'm trying to have multiple rows of images (each in a container I want to add other stuff to) stacked above each other, with the total height being dynamic.
When using flexbox for this, I can get the height to scale properly, and Chrome adjusts the width of the container divs appropriately. However, in Firefox, the containers around the images shrink their height, but keep their original width, which leads to huge gaps.
I tried a lot of combinations of adding min-width, flex-grow, flex-shrink, etc., but I can't get the Chrome behaviour in Firefox.
Here is a snippet illustrating the problem, it looks totally different on Chrome and Firefox. (the outer container has a fixed height for easier demonstration, but in my real use case its height is dynamic)
.verticalflex {
display: flex;
flex-direction:column;
height:200px;
}
.horizontalflex {
display: flex;
flex-direction:row;
min-height:100px;
max-height:500px;
height:500px;
}
.imgContainer {
height:100%;
}
img {
height:100%;
}
<div class="verticalflex">
<div class="horizontalflex">
<div class="imgContainer">
<img src="https://via.placeholder.com/500x500" />
</div>
<div class="imgContainer">
<img src="https://via.placeholder.com/500x500"/>
</div>
</div>
<div class="horizontalflex">
<div class="imgContainer">
<img src="https://via.placeholder.com/500x500" />
</div>
<div class="imgContainer">
<img src="https://via.placeholder.com/500x500"/>
</div>
</div>
</div>
It ends up looking like this in Firefox
UPDATE: I found a smaller example to illustrate the problem: On Firefox, the width of the .imgContainer is always 500px, regardless of its calculated height (which changes when you change the height of .verticalflex). On Chrome, the width of .imgContainer is always equal o the scaled down width of the image contained. What I want to achieve is that Firefox adjusts the width of .imgContainer according to the images scaled width as well.
.verticalflex {
display: flex;
flex-direction:column;
height:200px;
}
.flexitem {
min-height:100px;
max-height:500px;
height:500px;
}
.imgContainer {
display:inline-block;
height:100%;
background-color:red
}
img {
height:100%;
}
<div class="verticalflex">
<div class ="flexitem">
<div class="imgContainer">
<img src="https://via.placeholder.com/500x500" />
</div>
</div>
</div>
Behaviour on Firefox (I don't want this) vs Behaviour on Chrome (I want this)