Flex factor flex: 1
In the grid__row flex container, which is in the line, two flex elements - grid__item and img - each of them has flex: 1 .
This means that both elements will evenly distribute the available space in the container among themselves. In other words, 50/50, as in the illustration.
My suggestion: remove flex: 1 from img .
Space resulting from object-fit: contain
With object-fit: contain aspect ratio of the image is saved and scaled to object-fit: contain in the field.
As a result, there may be spaces on the left and / or right (portrait fit), or upper and / or lower (landscape is suitable).
This may be the reason that you see a βfillβ space to the left and right of the image.
If you try cover , all of the space will be used, but there it is cropped ( demo ).
Learn more about object-fit : fooobar.com/questions/94033 /.
overflow: hidden effect overflow: hidden
Regarding your side comment:
... overflow = hidden (which I really donβt understand what it is doing, but if I leave this, the img container will expand horizontally factor 2).
This is probably due to the minimal algorithm for calibrating the flexibility elements.
By default, the flexibility item cannot be smaller than the size of its contents.
However, this function can be overridden with overflow: hidden .
Read more here: Why doesn't a flex item reduce the size of the content?
Michael_B
source share