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

QR Code Component | Custom Properties, Translate

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

Solution retrospective


I had difficulties centering the card horizontally and especially vertically! Not sure about the flexbox stuff, it was my first contact with this subject.

Is it possible to center vertically without using flexbox?

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Md5 dalton•1,430
    @md5dalton
    Posted almost 3 years ago

    Hello Thullyo Damasceno 👋

    Your implementation of flex box to center the content vertically and horizontally if fine. However, let me suggest you use min-height instead of height because the former means that the element's height should be at least that high but may increase if the content needs more room. Here's how I'd modify the styling on the body element:

    body {
        ....
        /* height: 98vh; */
        min-height: 100vh;
        margin: 0;
    }
    

    There are several approaches that we can use to achieve this but we'll go through only 2 more below:

    • Grid
    • Position

    Grid is also an excellent way to go. It makes use the place-content property which combines align-content and place-content to center content perfectly in the middle of the page.

    body {
        min-height: 100vh;
        display: grid;
        place-content: center;
    }
    

    Last and least would be the use of position and translate properties but I recommend you stick with flex box instead:

    body {
        position: absolute;
        top: 50%;
        left: 50%;
        translate: -50% -50%;
    }
    

    I hope that gives you and idea on which you can choose on your next projects. 👌

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

    👾Hi Thullyo, congratulations on your solution!👋 Welcome to the Frontend Mentor Coding Community!

    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.Replace the <p> containing the main title with <h1> note that this title is the main heading for this page and every page needs one h1 to show which is the most important heading. Use the sequence h1 h2 h3 h4 h5 to show the hierarchy of your titles in the level of importance, never jump a level.

    2.Add the alt text to improve accessibility.The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of a slow connection, an error in the src attribute, or if the user uses a screen reader). ---> <img src="./images/image-qr-code.png" alt="QR Code Frontend Mentor">

    3.Use relative units like rem or em instead of px to have a better performance when your page content resizes on different screens and devices. REM and EM does not just apply to font size, but all sizes as well. To save your time you can code your whole page using px and then in the end use a VsCode plugin called px to rem to do the automatic conversion or use this website https://pixelsconverter.com/px-to-rem

    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
  • Vanza Setia•27,715
    @vanzasetia
    Posted almost 3 years ago

    Hello, Thullyo! 👋

    Congratulations on completing your first Frontend Mentor challenge! 🎉

    There are multiple ways to center an element in the middle of the page. I recommend reading the "The Complete Guide to Centering in CSS | Modern CSS Solutions". Right there, you can find different ways to center a div.

    I have some feedback on this solution.

    • img element must have alt attribute. The QR code is an important content of the page. So, it needs an alternative text.
    • For the container-title, swap the p tag with h1. Each page needs one h1.
    • I recommend adding rel="noopener" to any anchor tags that have target="_blank". It helps protect users of legacy browsers. I suggest reading the web.dev article to learn more about this.

    That's it! I hope this helps!

    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