Design comparison
Solution retrospective
-
For some reason flexbox would not center the container vertically so I had to do it manually with margins. Any idea what caused the problem? It happened in a previous project of mine so I'm curious. I use a Chromebook and Chrome with Caret as my text editor if that helps.
-
Is there a way to make the bg and text of buttons take the color of their div without directly giving them the color?
Feedback is greatly appreciated!
Community feedback
- @correlucasPosted over 2 years ago
πΎHello Renardo, congratulations for your new solution!
I've check your code and discover why wasn't getting centered, you've missed
min-height: 100vh
in the body. Note that the component (child) align to its parent (the body in this case). To have the proper align you've to give the min-height with some size to get aligned, in this case is100vh
thats makes the container align to the 100% of viewport height.See the code changes I did for you:
body { display: flex; min-height: 100vh; flex-direction: column; justify-content: center; align-items: center; } @media (orientation: landscape) .container { /* display: flex; */ flex-direction: row; max-width: 1000px; } .container { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 18px; max-width: 500px; /* margin: 10% auto 0; */ }
π I hope this helps you and happy coding!
Marked as helpful1 - @Illyaas4ShowPosted over 2 years ago
This is a very nice solution, it doesn't even have any issues, Well done!
- for centering using flex-box, try this:
body { display: flex; justify-content: center; align-items: center; height: 100vh; }
- That should center it right in the middle and if it doesn't, tell me so I can't check it.
I hope this helps! Happy coding!
Marked as helpful1@PinedevsPosted over 2 years ago@Illyaas4Show Thank you. I tried it and it works now. Looks like the height property was essential first.
0
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