Design comparison
Solution retrospective
I was unsure of how to center vertically the element in teh <body>. Can anyone help me with that?
Community feedback
- @super-simonPosted over 1 year ago
Hello. I recommend using flex for vertical centering. For example:
body { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
Don't forget to set min-height because, without this, the height of the body will not stretch to the entire screen.
Marked as helpful2@sergioaguiarPosted over 1 year agoThank you, @super-simon ! I've tried before using display: flex and diodn't get to the result because I was not using min-height.
I've made other minor changes and I think I am missing the exact design only by a few pixels in bottom margin under the <p>.
1 - @dionlowPosted over 1 year ago
Another option to center a div is to leverage flexbox. Flexbox turns the layout into a two dimensional axis: main axis and cross axis. You you can then center both axis if you would like.
The
align-items
property will align the items on the cross axis. Thejustify-content
property is used to align the items on the main axis.You can review concepts from flexbox here:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Marked as helpful1 - @Freezy699Posted over 1 year ago
I had the same problem and I wrote this in the container class in css (.container) : margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
Marked as helpful0
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