QR-code-compnent using CSS flex property

Solution retrospective
I am proud of the fact that I was able to create my first html,css challenge by taking a little help from mdn and css-tricks, next time I will try to complete it without any online help.
What challenges did you encounter, and how did you overcome them?I encounter the challenge of flex box property. When I made the body a flex and set justify-contents to center the 'attribution' div was in row with the card to i added flex-direction: column to make it go below the card but by doing so the justify-contents: center no longer worked, then i tried align-contents: center it still didn't work. Finally when i changed it to align-items: center the card was in the center of the screen.
What specific areas of your project would you like help with?code 1:
body{
display: flex;
flex-direction: column;
justify-content: center;
}
code 2:
body{
display: flex;
flex-direction: column;
align-content: center;
}
code 3:
body{
display: flex;
flex-direction: column;
align-items: center;
}
I want to know why code 1 and code 2 were not able to center the body while code 3 does it.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @KapteynUniverse
When flex-direction is set to column,
align-items: center;
centers the content horizontally, andjustify-content: center;
centers it vertically. If flex-direction is row, it works the other way around.The problem you're facing is that the <body> element is only as tall as its content. That means you don't see the vertical centering visually but it works. To fix this, you need to set a height. Like you did here but instead of using margin-top, apply
min-height: 100vh;
.Also, avoid using percentage-based heights (especially with low values), as they often behave unpredictably.
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