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 Component solution using HTML and CSS

@Slaks97 180

@Slaks97

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


Hi everyone! I am not convinced of my solution!

  1. In order to be able to center the .container div both horizontally and vertically using Flexbox, I set min-height: 100vh on the body. It was a shot in the dark which seems to be working. Could someone remind me of the role of height in relation to flexbox? I've not fully grasped it.

  2. I gave that same .container div margin: 100px auto as I also wanted free space at the top and bottom. Is that correct or is there another way?

  3. I didn't set a width on the body as it didn't seem to make much difference. Should I have done?

Many thanks!

Community feedback

Marjan 280

@MarjanZivkovic

Posted

Hi @SLAKS97! Congrats on completing the project! Shots in the dark sometimes hit the target :) Just kidding!

Yes, that is one of the ways to center a container on the page, setting the body as a flex container. align-items: center will center your container vertically (by default). The height of your body is dictated by the height of your container. In this case, your container is high enough so you can even omit min-height: 100vh on the body, it'll be the same. You want to use min-height: 100vh on the body when your container is less high. In this way, it'll be perfectly centered vertically in the middle of the screen.

Horizontally you'll use justify-content: center (by default) to center your container on the page. In your case, it's not necessary since you're having margin: 0 auto on the container, which does the same thing.

You can even remove display: flex and align-items: center and min-height: 100vhon body and you'll get the same result (try it out).

As for the width, you don't have to set the width: 100% (especially not in px). By default, body, divs, and all the other block elements already have the width 100%, meaning all the available width of the screen.

Hope some of this makes sense. Good luck!

Marked as helpful

0

@Slaks97 180

@Slaks97

Posted

Hi @MarjanZivkovic!

It all makes perfect sense :)

I've applied all that you suggested and my code looks a lot cleaner for it, so thanks very much!

1

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