QR-code "align the element vertically and horizontally in browser"
Design comparison
Solution retrospective
It is difficult to align items / div vertically on a browser page.
I am not sure if the mobile design needs to be modified as there is only one element on the page that fits the mobile screen perfectly.
Let me know if you have any comments Thank you Gwen
Community feedback
- @HassiaiPosted over 1 year ago
To center .child on the page using flexbox, add min-height:100vh; display: flex; align-items: center: justify-content: center; to the body
body{ min-height: 100vh; display: flex; align-items: center; justify-content: center; }
there is no need to give ,.child position: absolute and its properties and a margin value.
Use relative units like rem or em as unit for the padding, margin, width values and preferably rem for the font-size values, instead of using px which is an absolute unit. For more on CSS units Click here and here
Hope am helpful.
Well done for completing this challenge. HAPPY CODING
Marked as helpful0@Gwen-legoPosted over 1 year agoHi @Hassiai,
Thank you for the feedback, the link you provided are really helpful. I do understand the importance of units, now 😄.
Have a good one. Cheers Gwen
1 - @0xabdulkhaliqPosted over 1 year ago
Hello there 👋. Congratulations on successfully completing the challenge! 🎉
- I have other recommendations regarding your code that I believe will be of great interest to you.
CSS 🎨:
- Looks like the component has not been centered properly. So let me explain, How you can easily center the component without using
margin
orpadding
.
- We don't need to use
margin
andpadding
to center the component both horizontally & vertically. Because usingmargin
orpadding
will not dynamical centers our component at all states
- You already using
Flexbox
for layout, but you didn't utilized it's full potential. Just add the following rules to properly center the component.
body { min-height: 100vh; align-items: center; }
- Now remove these styles, after removing you can able to see the changes
.child { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
- Now your component has been properly centered
.
I hope you find this helpful 😄 Above all, the solution you submitted is great !
Happy coding!
Marked as helpful0@Gwen-legoPosted over 1 year agoHi, @0xAbdulKhalid
Thank you very much for your comment, I was indeed confused with the vertical alignment. It makes total sense now.
Have a great day.😄
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