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

QR code using flexbox in CSS

alihaydar28•30
@alihaydar28
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 putting some spacing between text and card a bit challenging so I hope anyone can help. also any feedback would be great since i'm still a beginner

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • orphandeity•530
    @orphandeity
    Posted over 2 years ago

    Wow, your project looks great!

    Looking at your code, I think you would benefit a lot from using responsive units like em and rem. These units are based on the font-size and will help keep things consistent and prevent you from having to think with pixel-perfect precision. They are used in place of px and are great to use for margin, padding & font-size. When you are first learning about these units, I would start with and focus on rem and then use em when you need more control.

    Instead of trying to explain how this works myself, I will point you towards an article that I think explains it pretty well.

    There are also responsive units that are based on the window size... these are vh and vw. To illustrate, 100vh is equal to the entire height of the window and would effectively make the element fullscreen. 50vh would make the element take up half the window and vw does the same thing for width.

    Here is a really good article on the subject of viewport units.

    Marked as helpful
  • Hassia Issah•50,390
    @Hassiai
    Posted over 2 years ago

    Replace <div class="card"> with the main tag to fix the accessibility issues. click here for more on web-accessibility and semantic html

    There is no need for the <br> in the html. there is no need to give the html and the bosy a width and heigh value.

    To center .card on the page using flexbox, add min-height : 100vh to the body.

    For a responsive content, give .card a max-width value and increase the padding value. max-width: 320px padding: 16px.

    Give the img a max-width of 100% instead of a width for a responsive image. This challenge does not require a box-shadow.

    Give .text a margin value for all the sides, text-align: center and a font-size of 15px which is 0.9375rem, this will be the font-size of both p and h1.

    Use relative units like rem or em as unit for the padding, margin, width values and preferably rem for the font-size values, instead of using px which is an absolute unit. For more on CSS units Click here

    Hope am helpful.

    Well done for completing this challenge. HAPPY CODING

    Marked as helpful
  • Jeroen Leijnse•1,420
    @jrleijnse
    Posted over 2 years ago

    Hey there! Great job completing your first challenge! 🎊

    I have some suggestions for your code that might interest you.

    HTML 📄:

    • Instead of using the <div> tag for your containers, try using some semantic HTML to provide more meaning to it, for better SEO. For example, instead of using <div> you could use the <main> or <section> tag. For the element with the classname attribution you could use the <footer> tag.
    • If an <img> like in this case the QR-code, leads to a website or links to someplace else, try to provide a more descriptive text of that in your ALT text, for example: QR code that leads to frontendmentor.io

    CSS 🎨:

    • Removing the margin-top from the <h1> element and removing all margin from the <p> element and then adding some padding to the <div class="text"> should fix your issue.
    • To make your project more responsive and adaptable (in this case as well: especially when you start building bigger and bigger projects), I would suggest to use rem instead of px. This basically means that all sizing will be calculated in relation to the root element (rem). To set the standard font-size for the root element, you can provide a font-size inside the HTML element inside your CSS. For example: html {font-size: 15px;}.

    For more information on this topic, you can read the following article: PX or REM in CSS? 📘

    • To make your solution responsive for different devices and screen widths, you can create a media query inside your CSS file and set the breaking point (i.e. the moment your media query gets triggered based on the width of the viewport). For example: @media (max-width: 375px) { ***Place your CSS code here, just like you would in a regular CSS file***}.

    For more information on this topic, you can read the following article: Media queries 📘

    • An easy way to quickly and automatically center your <main> element inside the <body> of your page, is by setting the following properties onto the <body> element inside your CSS like so: body { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }

    I hope you find my suggestions useful, and above all: the solution you provided is very good!

    Keep it up 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

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