Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

QR-code "align the element vertically and horizontally in browser"

Gwen-lego 190

@Gwen-lego

Desktop design screenshot for the QR code component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

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

Hassia Issah 50,670

@Hassiai

Posted

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 helpful

0

Gwen-lego 190

@Gwen-lego

Posted

Hi @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

@0xabdulkhaliq

Posted

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 or padding.
  • We don't need to use margin and padding to center the component both horizontally & vertically. Because using margin or padding 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 helpful

0

Gwen-lego 190

@Gwen-lego

Posted

Hi, @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 GitHub
Discord logo

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