Deal with images of different aspect ratio inside grids
What I get is the thing you can see in the pic attached. This is the code behind it:
I'd like some ideas on how to deal with a fluid image inside a grid while keeping the original aspect ratio and also having it look nice

29 Replies
you might want this:
https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
also,
//
is an invalid comment in css
also, try removing the heightI'm using SCSS
Removing the height is what causes the problem, if I add height: 100% it works
I tried this but it doesn't do anything, ecept for none that displays everything worse
https://byteshaman.github.io/my-tv-list/ not really a CodePen link, but the code can be edited directly from the browser easily enough (you have to delete height: 100% to notice the problem, and there won't be a red bg color)
this is what i got

on
.poster
, i've added this:
and on .poster__image
i've replaced everything with this:
that random image is 600x400Ohh sweet, I didn't think about using flex
im using flex just to center the image
and not for the flex things
Ok I'm doing some tests
alright
I wasn't aware of the aspect-ratio thing, it's really cool
it's pretty useful
oh, wait
i fixed a bug on that
this is the bug: taller images aren't being cropped

the fix is simple - use this for the
.poster__image
:
and images of any size will fit in here
Oh neat
Thank you
is this what you wanted?
I'll need to check if the Lighthouse error is gone
it won't be gone
specially since you didnt even say anything about it before
I said it here when talking about the aspect ratio
The biggest problem is performance, and I'm working on it
that's probably solved as an accident
It's this one I referred to

I set a new way to get my images, so that I only choose the width (300px) so it might work better now I'm doing some tests
you have a height of 150px minimum
maybe start from there, instead of the width, if you can
i mean, width
sorry
150px minimum of width
300px is good
Yeah that's because on smallest screens I want to display 2 posters
i know
i just misread the grid code
Oh no worries
but honestly, i wouldn't worry about that message on lighthouse
you can, however, set a fixed width and height using properties
I'd just like to achieve a perfect score as a challenge :>
you'll be better off finding an unicorn on a pink moon sunset while perfectly sober
100% is possible, but it doesn't always show how good or bad the site is