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

Responsive QR Code with plain HTML and CSS

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

Solution retrospective


Hey guys.. new guy here, few questions wanna to ask

  1. Not sure what is the correct name convention for css class names, is there any recommendation?

  2. is there anything that I can refactor to keep it DRY

Thanks

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Steven Portas•610
    @satrop
    Posted over 2 years ago

    @KyrieeWen - great question.

    As a rule of thumb CSS classes are dash-separated, so I would take CreditCardForm and change that to credit-card-form. Camel case is usually reserved for JS.

    So if you couple this naming convention with BEM, Block, Emelent, and Modifier you can keep things clean and easy to "human read" in the HTML layer.

    Let's take your credit-card-form for instance. This will sit on the parent <form> and has children. Suppose your form has two buttons, submit and cancel following the BEM naming convention their class names might look like this...

    credit-card-form__button - this would sit on both buttons and give general styling to them. The __button is the "E" (element) in BEM. Now we want to style one of the buttons differently. It might look like this...

    credit-card-form__button--cancel - this would sit on just one of the buttons and give different styles to that button, it has the modifier class attached to it denoted by the --cancel double dash followed by the name.

    You want to keep your class name "human readable" to make it easy for future you or other devs to come in and quickly see what's what.

    To add to this, BEM doesn't have logic for grandchildren baked in. And so this isn't a rule at all but something I might do (anyone please feel free to comment about this idea), using your button as an example, might use a single underscore, like this...

    credit-card-form__button_button-icon - this might get a little long so you could keep it simple (ish) and stick to just using the BEM method adding a class name to a grandchild...

    credit-card-form__button-icon - this doesn't feel great to me.

    Hope this helps!

    All the best, Steve

    Marked as helpful
  • Adriano•42,890
    @AdrianoEscarabote
    Posted over 2 years ago

    Hi Kyrie, how are you? Welcome to the front-end mentor community! I really liked the result of your project, but I have some tips that I think you will enjoy:

    To align some content in the center of the screen, always prefer to use display: flex; it will make the layout more responsive!

    body {
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        min-height: 100vh;
    }
    

    Avoid using width as this ends up making it difficult to make the project resonant, prefer using max-width!

    The rest is great!

    I hope it helps... 👍

  • Mike Oram•230
    @SlothSan
    Posted over 2 years ago

    Hello,

    Your CSS class names seem fine to me, they are descriptive and are in kebab case.

    As the other person pointed out, look at SCSS and then you can re-use parts of your CSS so that you don't end up repeating yourself.

    It will also allow you to nest selectors inside of other selectors to clean up the code.

    Looks great, good work!

  • Steven Portas•610
    @satrop
    Posted over 2 years ago

    Hi there!

    A great place to start for CSS naming convention is the BEM method. BEM stands for Block, Element, Modifier. I wont go over the details here, there are a lot better wrights out there than myself. So a wee Google search will get you off a running in no time. I use it all the time.

    As for keeping the CSS stack DRY, I suggest SCSS. If you’ve never used SCSS before I can be a little/a lot daunting but again, there is a plethora of tutorials out there to get you up and running but two really good sources I go to and HIGHLY recommend is a chap on YouTube, Kevin Powell. And a lady who’s channel is called “Coder-Coder”, I can’t recall her name. But these are great places of research.

    Hope this helps and keep up the great work!

    All the best, Steve.

    Edit. Just realized this was a MD editor! So…

    Kevin Powell

    Coder-Coder

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

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub