Design comparison
Solution retrospective
This is my first attempt here, I hope I did everything right. I struggled more with setting up GitHub than solving the challenge.
My major problem, during the challenge, was positioning the div which holds the image to the center of the page. If you can show me a more practical way to do that, I would be very happy.
Community feedback
- @MelvinAguilarPosted about 2 years ago
Hi @K-Muzslay ๐, good job for completing this challenge and welcome to the Frontend Mentor Community! ๐
Answering your question here are some suggestions to improve your code:
There are two modern CSS techniques to center elements
Using flexbox layout:
body { width: 100%; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }
Using grid layout
body { width: 100%; min-height: 100vh; display: grid; place-content: center; }
More information:
- The Complete Guide to Centering in CSS
- A Complete Guide to Flexbox (CSS-Tricks)
- How TO - Center Elements Vertically (W3Schools) |
- CSS Layout - Horizontal & Vertical Align (W3Schools)
And remove:
main { /* margin: 0; */ /* position: absolute; */ /* top: 50%; */ /* left: 50%; */ /* -ms-transform: translate(-50%, -50%); */ /* transform: translate(-50%, -50%); */ }
Another tips:
- Use
max-width: 360px
to.container
selector instead of width. - Use
margin: 0.625rem
ormargin: 10px
in thecontainer
selector so that it has some space when viewed on mobile devices.
I hope those tips will help you.
Good Job and happy coding !
Marked as helpful1@K-MuzslayPosted about 2 years ago@MelvinAguilar Thank you so much! I was sure it can be solved with flexbox, I tried but I was not familiar with the "vh" relative unit. Now I'll keep it in mind.
I haven't learnt grid yet, I will revisit this when I'm at it.
Thank you for the extra tips too!
1
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