Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 years ago

QR Code Component solution using HTML and CSS

@Slaks97•180
@Slaks97
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

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!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Marjan•320
    @MarjanZivkovic
    Posted about 2 years ago

    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

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub