Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Project 2 - QR Code

Angus Turnbull•70
@echoturnbull
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


My second project solution.

A few things I had trouble doing. I was unable to figure out why i could not center the entire container into the center of the page. Hopefully this time around I have fixed a few things from the first project, such as phone compatibility.

If anyone takes the time look at this and provide a comment then thank you very much in advance!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Kehinde•680
    @jonathan401
    Posted almost 3 years ago

    Hey @echoturnbull 👋🏽. Congratulations on completing this challenge 🎉. You did good 👍🏾. A few things to note: html

    • Your html document shouldn't contain more than one body element. So you should remove the body tag surrounding your h1 element.
    • There is really no need for you to wrap your h1, p tags in extra divs or other wrappers. Since this challenge only contains an image, h1 and p elements. Doing this will make your html a little bit more neat, and you don't have to write a whole lot of CSS. But the method you used is also perfectly fine since you could practice using classes 💪🏾.

    CSS To center the container, you have to give a min-height property to the body element because by default, block level elements have a height of 0 and only take the height of their children. The style definition for the body element becomes:

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

    And any other style you want to give the body.

    • To make your image more responsive, there is no need to set a height and width property to it. This could cause layout issues later on. So the style definition for the image becomes:
    display: block;
    width: 100%;
    object-fit: cover;  
    

    Should be enough.

    • remove the margin: 0 auto 0 auto; from the main selector. The display: flex you added to the body selector will center the main element horizontally and vertically.

    • Avoid using absolute values like px to for defining size or padding of elements. This could cause issues with accessibility.

    • There is no need to set width to h1 and p tags, the text-align: center; property you added to the body element would make sure that the elements are centered horizontally.

    Sorry that got too long. You did really good 💪🏾. Once again, congrats on completing this challenge 🎉🎉

    Marked as helpful
  • Adriano•42,890
    @AdrianoEscarabote
    Posted almost 3 years ago

    Hi Angus Turnbull, how are you?

    I really liked the result of your project, but I have some tips that I think you will like:

    1- We have to make sure that all the content is contained in a reference region, designated with HTML5 reference elements or ARIA reference regions.

    Example:

    native HTML5 reference elements:

    <body>
        <header>This is the header</header>
        <nav>This is the nav</nav>
        <main>This is the main</main>
        <footer>This is the footer</footer>
    </body>
    

    ARIA best practices call for using native HTML5 reference elements instead of ARIA functions whenever possible, but the markup in the following example works:

    <body>
         <div role="banner">This is the header</div>
         <div role="navigation">This is the nav</div>
         <div role="main">This is the main</div>
         <div role="contentinfo">This is the footer</div>
    </body>
    

    It is a best practice to contain all content, except skip links, in distinct regions such as header, navigation, main, and footer.

    Link to read more about: click here

    2- Why it Matters

    Navigating the web page is far simpler for screen reader users if all of the content splits between one or more high-level sections. Content outside of these sections is difficult to find, and its purpose may be unclear.

    HTML has historically lacked some key semantic markers, such as the ability to designate sections of the page as the header, navigation, main content, and footer. Using both HTML5 elements and ARIA landmarks in the same element is considered a best practice, but the future will favor HTML regions as browser support increases.

    Rule Description

    It is a best practice to ensure that there is only one main landmark to navigate to the primary content of the page and that if the page contains iframe elements, each should either contain no landmarks, or just a single landmark.

    Link to read more about: click here

    Prefer to use rem over px to have your page working better across browsers and resizing the elements properly

    The rest is great!!

    Hope it helps...👍

    Marked as helpful
  • Lucas 👾•104,160
    @correlucas
    Posted almost 3 years ago

    👾Hi , congratulations on your solution!

    Great solution and a great start! From what I saw you’re on the right track. I’ve few suggestions for you that you can consider adding to your code:

    1.Fix the alignment of the whole content using flex and min-height to manage the vertical alignment and make everything centered.First of all put min-height: 100vh to the body to make the body display 100% of the viewport height (this makes the container align to the height size that's now 100% of the screen height) size and display: flex e flex-direction: column to align the child element (the container) vertically using the body as reference.

    body {
        font-family: 'Outfit', sans-serif;
        background-color: hsl(212, 45%, 89%);
        text-align: center;
        min-height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
    }
    

    2.Keep the image responsive. To manage the image size, you don’t need to define the width and height together, if you do it with different values this will make the image lose proportions, to keep the image responsive and respect the container size use img { display: block; max-width: 100%} this way the image resize with the container whatever its size.

    3.Add a margin of around margin: 20px to avoid the card touching the screen edges while it scales down.

    4.Use relative units as rem or em instead of px to improve your performance by resizing fonts between different screens and devices. These units are better to make your website more accessible. REM does not just apply to font size, but to all sizes as well.

    Here's my solution for this challenge if you wants to see how I build it: https://www.frontendmentor.io/solutions/qr-code-component-vanilla-cs-js-darklight-mode-nS2aOYYsJR

    ✌️ I hope this helps you and happy coding!

    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

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