Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 4 months ago

QR Card Component HTML CSS

vite
Ty Maraist•10
@tcmaraist
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I am most proud of figuring out how to connect Google Fonts and getting the margins and border-radius right despite being confused by Figma.

What challenges did you encounter, and how did you overcome them?

I don't understand Figma well, and some of the values seem off. For example the border-radius for the card said 25%, but that was way too much and i landed on 2%.

What specific areas of your project would you like help with?

I think I managed to get the font looking decent, but it doesn't feel perfect to me. I could use some guidance there.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Aakash Verma•9,500
    @skyv26
    Posted 4 months ago

    Hi @tcmaraist, 👋

    Great job on the project so far! Below are a few suggestions to enhance the semantics, responsiveness, and readability of your code. Let’s walk through them one by one with simple examples for clarity:


    1. Centering the Card to the Screen 🌟

    Currently, the card class is centered using margin-top, which doesn’t adapt well to different screen sizes. A better approach is to refactor the body CSS as follows:

    Refactored Code:

    .body {
        background-color: #d5e1ef;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-family: "Outfit", serif;
        min-height: 100vh; /* Ensures the content fills the entire screen height */
    }
    
    .card {
        height: auto; /* Let the content define the height */
        width: 100%; /* Make the card fluid */
        max-width: 320px; /* Maintain a maximum width for readability */
        border-radius: 2%;
        background-color: white;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center; /* Fixed typo: tex-align -> text-align */
    }
    

    This change ensures the card is vertically and horizontally centered, even on smaller screens. Imagine reading a business card: you want it perfectly centered for easy focus.


    2. Avoid Using Fixed Heights for the Card 🏗️

    Setting a fixed height property limits flexibility. For instance, if you add more content or increase padding, the card might overflow. Instead, let the inner elements decide the height by using padding and margins.

    Refactored Code:

    .card {
        padding: 20px; /* Add padding to manage spacing */
        height: auto; /* Dynamic height adjustment */
        width: 100%;
        max-width: 320px; /* Ensures responsiveness */
        border-radius: 2%;
        background-color: white;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    

    Think of this like resizing a box based on what you’re putting inside it — the box adjusts dynamically, rather than spilling over or leaving empty space.


    3. Make the Card Responsive 🖥️

    Using a fixed width (e.g., width: 320px) can break the layout on smaller or larger screens. Switching to max-width makes the card fluid and adaptive.

    Example:

    On mobile devices, the card will shrink proportionally instead of staying fixed at 320px.

    Refactored Code:

    .card {
        width: 100%; /* Fluid width */
        max-width: 320px; /* Restricts to a reasonable maximum */
    }
    

    4. Use Semantic Tags for Better Accessibility 🎯

    The p tag is currently being used for the card’s main heading. Since it conveys the primary purpose of the card, an h1, h2, or h3 tag would be more appropriate. Semantic tags improve accessibility for screen readers and provide better document structure.

    Current Code:

    <p class="card-title">
        Improve your front-end skills by building projects
    </p>
    

    Suggested Code:

    <h2 class="card-title">
        Improve your front-end skills by building projects
    </h2>
    

    Imagine a search engine or screen reader trying to understand the card. Using an h2 signals, "This is important content!" — just like a bold heading in a newspaper article.


    Summary ✅

    1. Centering: Use min-height: 100vh for the body and remove margin-top from the card.
    2. Dynamic Height: Avoid fixed heights; let inner elements control the size.
    3. Responsiveness: Replace width with max-width.
    4. Semantic Tags: Replace the p tag with a heading tag (h2) for better accessibility and structure.

    Keep up the great work, and feel free to reach out if you have any questions! 🚀

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