
Design comparison
Solution retrospective
I always found it difficult to center element inside a div.
display: flex;
align-items: center;
justify-content: center;
Sometimes this code block would work. But sometimes it fails to center any element. In this particular case, when centering the card container in the main body. I did put the property block above in my parent container but it doesn't work. Did some research and asking for help from other friend, and come up with this solution
body {
display: grid;
place-content: center;
min-height: 100vh;
}
What is the best practice for centering an element inside a div?
In which situation I should use the first code block and the second code block in my code?
Community feedback
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