
Solution retrospective
As a beginner found it useful to start with this challenge. Had a few hurdles and had to go through google to get some solutions. Was never able to center a div vertically a topic I need to learn.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @MikeBeloborodov
Let's say that you have a body and 1 div, to center this div inside the body you need to do this
body { height: 100%; display: flex; justify-content: center; align-items: center; background-color: green; } div { width: 100px; height: 100px; background-color: red; }
If you do this and remove height on your body, then it won't center vertically, because body does not stretch to the full height without content. But if you add height - then it's a box that covers the full screen and your div will be in the center because justify-content centered it horizontaly and align items verticaly. You can add some background color on body to see how it stretches.
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord