Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 1 year ago

Solution using flex-box

Juan Galvez•50
@Galvez121
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Could anyone help me? I tried to center the div in the middle of the website using flex-box justify-content, but It did not work out. I did it using margin instead.

Any bad practice in HTML or CSS? Any changes that would make my code cleaner?

Thank you ^^

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

  • FFerDev•30
    @FFerDev
    Posted over 1 year ago

    Greetings ♥. The issue with trying to vertically center the component arises from not giving it a "defined" height. By default, the height will adjust to the height of its contents, meaning it will only occupy the necessary height, rendering the attempt to vertically center it futile. The solution would be to provide a height to the parent element of the element you want to center, for example, a min-height: 100vh. This way, it will have the space needed to be vertically centered.

    Marked as helpful
  • Rebecca Padgett•2,100
    @bccpadge
    Posted over 1 year ago

    Hello @Galvez121. Congratulations on completing this challenge!!!🎉

    To answer your question, you can use Flexbox or CSS Grid to center your component in the middle of the page.

    More info📚:

    • Flexbox
    • CSS Grid

    You can add these styles on the <body> element. It doesn't matter which CSS Layout you choose the result is the same.

    Flexbox

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

    CSS Grid

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

    HTML 📃:

    • Every website should have at least one landmark so you can wrap your content using <main> tag.
    • When writing HTML, stick to class names because Ids are mainly used for JavaScript.
      • Ids in HTML

    Hope this helps you and have any other questions I would be glad to help you and just let me know✌🏼

    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 1st-party linked stylesheets, and styles within <style> tags.

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.

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