Design comparison
Solution retrospective
The property "margin: auto" only centralizes it horizontally, but I would like to do it vertically as well, so, how can I centralize the #container div, both horizontally and vertically?
Community feedback
- @Priya366Posted over 2 years ago
Hi Felipe! You have done an awesome work and your code is easy to read. Good job!
As per your query, You can center container by styling body as follows:
** body { display: flex; justify-content: center; align-items: center; height: 100vh; } **
Really hope this will be helpful.
!!!One more thing, do check and improve your accessibility issues too!!!
Marked as helpful1 - @denieldenPosted over 2 years ago
Hi Mateus, great work on this challenge! 😉 using
margin
to center elements might be almost deprecated by nowHere are a few tips for improve your code:
- add
main
tag and wrap the card for improve the Accessibility - remove all
margin
fromcard
class - use flexbox or grid to the body to center the card. Read here -> best flex guide
- after, add
min-height: 100vh
to body because Flexbox and Grid aligns child items to the size of the parent container
Overall you did well 😁 Hope this help!
Marked as helpful1 - add
- @mjbagaPosted over 2 years ago
Hi, Mateus. You can centralize elements inside a grid or flex vertically and horizontally using "place-items: center;". It's the short version of "justify-items: center;" and "align-items: center;".
For flex, depends on which direction if it's column or row, justify-items or align-items.
For non-grid or non-flex, try "vertical-align:" sub or middle, etc. You'd have to manually check.
Last would be just adding padding on inline elements.
Marked as helpful1
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