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

QR Code Component - First challenge finished!

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

Solution retrospective


Hey! Just finished my first challenge on FrontEndMentor but I have a question.

When I apply align-content: center to my flex container it won't align it in the middle of the page vertically. I don't know if I'm missing something or using a wrong attribute for what I'm trying to do.

My solution to make it look somewhat in the middle was to apply a margin-top to the container but I don't know if this is a good way to do it or not.

I will very much appreciate the feedback.

Thanks! :)

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Melvin Aguilar 🧑🏻‍💻•61,020
    @MelvinAguilar
    Posted almost 3 years ago

    Hi @luisoliverosrdn, good job for completing this challenge! 👋

    Here are some suggestions to improve your code:

    • To align a element it in the middle of the page vertically with flexbox you need to set the height of the containing element, Although the flex layout should be used in your body to center the .card element, height: 100vh;

    • Image dimensions become larger than required when viewed from a higher resolution

    I suggest you modify the styles in this way:

    .body {
        width: 100%;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background-color: hsl(212, 45%, 89%);
    }
    
    .card_container {
        /* display: flex; */
        /* flex-direction: column; */
        /* align-items: center; */
        /* justify-content: center; */
        /* margin: 10% auto; */
        /* width: 17vw; */
    
        background-color: white;
        max-width: 230px; /* This set the maximum width of  the .card*/
        border-radius: 10px;
        padding: 10px;
    }
    
    .card_img {
        /* width: 15vw; */
        /* margin: 0.5rem; */
    
        width: 100%;
        height: auto;
        object-fit: contain;
        border-radius: 10px;
    }
    
    .card_text {
        /* width: 15vw; */
        text-align: center;
        font-family: outfit;
        margin: 0.5rem 0;
    }
    
    • You can use either the CSS @import rule to import the font-family Reference

    In your CSS file add:

    @import url("https://fonts.googleapis.com/css2?family=Outfit:wght@500;700;900&display=swap");
    

    And use it as follows

    font-family: "Outfit", sans-serif;
    
    • Try to use semantic tags in your code. More information here:

    Without semantic tags:

    <body>
       <div class="card">
       </div>
    <body>
    

    With semantic tags:

    <body>
       <main class="card">
       </main>
    <body>
    

    More information:

    A Complete Guide to Flexbox (CSS-Tricks) |

    https://www.w3schools.com/howto/howto_css_center-vertical.asp |

    CSS Layout - Horizontal & Vertical Align

    I hope those tips will help you.

    Good Job !

    Marked as helpful
  • Nicolás Órdenes•50
    @nico-or
    Posted almost 3 years ago

    Hi. First of all congratulations on your first submission!

    align-items

    Regarding your issue with align-items: center. That property sets the position of it's childs, not the container itself.

    If I understood correctly, you wanted to center de <div class="card_container"> with align-items: center. To do that you would need to nest the div inside a flex column. Something like

    <body>
      <div class="card-container">test</div>
    </body>
    
    body {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    

    I always use the CSS-Tricks guides for reference with flexbox and grid. For example, the align-items entry in the guide.

    Some other things I spotted on your solution

    body element size

    The body element isn't covering the whole screen, despite background color apearing in the whole screen (I'm actually surprised by that). That's because percentage-based sizes are measured relative to the parent container and the body doesn't have a parent. You need to use viewport sizes.

    body {
      height: 100vh;
    }
    

    card_container width

    I noticed that the .card_container behaves weirdly, specially around the media-query. I think you can get better results using the CSS clamp function.

    I hope that some of that might have helped. Cheers!

    Marked as helpful
  • Esteban•340
    @estebanp2022
    Posted almost 3 years ago

    I come across the same problem (not sure what I'm missing). I fix it by using the Transform/Translate properties and this works every time. Just include the following on the selector of whatever you're trying to center both vertically & horizontally:

    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);

    Hope this helps!

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