Design comparison
Solution retrospective
- How can one place a div at the center of a page/screen?
Community feedback
- @denik1981Posted over 3 years ago
How can one place a div at the center of a page/screen?
- Give your body tag a min-height of 100vh so that it grows to cover the viewport.
- Convert your body element in a flex-container with display:flex.
- Give your div a margin:auto so it can create even margins in the both axis.
One thing that is amazing about the flex container is that the margin auto on the y-axis behaves as you would expect. This is something you couldn't achieve with a regular block element where you can only center a child element on the x-axis.
Marked as helpful1@FlightfulKiwiPosted over 3 years ago@denik1981 Appreciate the feedback. I'm extremely new at CSS/HTML as all can tell. I've got soooo much more to learn. I don't entirely understand everything you said but I'll continue learning and resubmit an improved solution to this assignment - if allowed. Thanks again!
0 - @FarisPalayiPosted over 3 years ago
body { min-height: 100vh; display: grid; place-items: center; // or you can use place-content }
Here's a quick video
Marked as helpful0@FlightfulKiwiPosted over 3 years ago@FarisPalayi You even added a video. Can it really be this simple???? OMG!!!! Thank you so much. As I said above, I'm new to this but I very much appreciate you taking the time to assist. I'll be back on this assignment. :-)
1
Please log in to post a comment
Log in with GitHubJoin 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