Can't center div vertically.
Hello! I managed to center my car div horizontally but can't center vertically. Please help!
10 Replies
To expand on Zach's (correct) answer, by default flex is only as big as it needs to be, and in this case the card is only as big as the image. So technically it was centered vertically 😜
Thank you so much man! It worked!
I was literally struggling with it
I was waiting for Shayokh's questions to explain further 😛
Making the html and body elements 100% high (I would have gone with 100vh, but zach's not fully wrong lol) you now have vertical height to play with
np
100vh is bad for mobile
it's Good Enough™️
and with the new relative units rolling out it'll be even less good!
But let's not get off-topic here
it doesn't adapt to UI element changes on scrolldown.
over 50% of the planet use mobile, use a better solution 🤣
I do that enough…
I should get b1 onto you beck