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 project done with Flexbox and Semantic HTML

@Meobot

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


I added 100px of margin-top to get the card centered vertically, but I was wondering if there was a better practice I could use going forward.

Community feedback

Elaine 11,400

@elaineleung

Posted

Hi Meobot, well done completing your first challenge, and welcome to Frontend Mentor! Yes, there definitely is a better practice, and it's what Nikola described above. Since you already are using flexbox in your body, you can just add align-items:center and min-height: 100vh, and then remove the margin you put in. You'd always need a height when centering because if there's no extra space around the container, the browser would not be able to center the element because centering requires equal spacing around the element. Also, this code works if you only got one child element to center; if you have more children elements (like a footer for example), you'd need to change your flex properties a bit.

Once again, great job and happy coding!

Marked as helpful

1

@Meobot

Posted

@elaineleung Thanks a ton, that helps it make sense.

0

Account Deleted

Hi, congrats on finishing the challenge! 💪

There is a better practice to center the div, and here's how you can do it by using the flexbox.

On a parent element add this declaration block:

min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;

And that's it! Here you can read more about it: Centering in CSS

I hope this was helpful.

Happy coding. 👨‍💻

Marked as helpful

1

@Meobot

Posted

@kom42ec Thank you, that works perfectly!

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