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

QR Code for Desktop and Mobile

Lauren Delmar•100
@lrdelmar
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I found it difficult to align the qr component in the center vertically so I did a bit of searching around and found a solution on Stack Overflow, which was to use absolute positioning and set the position to 50% and use transform translate by -50%.

I am wondering if this is best practice? I am able to center content using flexbox but this only seemed to be working horizontally and not vertically. When using align-content it didn't seem to move. I thought maybe I needed to set a height for this to work but it didn't have any effect.

I had originally created padding around the qr image however this created problems with the border-radius, so I changed this to margin and set the image to 90% width instead.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Mtalafa•350
    @Mtalafa
    Posted almost 2 years ago

    Lauren Delmar, well done for completing your first challenge. The way you centered it it`s not wrong, but you can also do it with flexbox in the following way: display: flex; align-items: center; justify-content: center; height: 100vh; You can also check my solution, I centered it with flexbox. Hope this helps. Happy coding!

    Also, I usually delete the footer from my projects. If you have the footer as well and you display flex on the body you should use flex-direction: column; as well

    Marked as helpful
  • Abiel Bright•260
    @abie237
    Posted almost 2 years ago

    Well done bro ! You already have the habits of a great programmer ! RESEARCH is key !

    what i propose is that inside the Qr Container you could create two respective divs ; one for the image and one for the text content

    To fit the image in its div use width:100%,height:100%,and the object-fit: cover.

    Marked as helpful
  • Guerinik Abderrahmane•460
    @AbderrahmaneGuerinik
    Posted almost 2 years ago

    Congrats for finishing this project ! but you can improve your code

    • i noticed you used position : absolute to center the container but no need, you've already used display:flex and set align-items and justify-content to center and its enough to center the container.

    • use CSS variables.

    • use BEM methodologie for naming classes.

    Enjoy coding

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