Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Desktop design screenshot for the QR code component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Something I found a little difficult with this project was the dimensions, it felt like I was constantly typing in different px amounts to try and get everything spaced out correctly.

Something I am unsure about with my code is how it will work on different display sizes and if it is scaleable / mobile friendly. Max-width and @media stuff was confusing to me when i looked into it.

Also i am unsure of my decision to use <br> line breaks instead of something that automatically flex's the text how I'd like

I would like to get better at structuring my HTML, it felt like i was making random things at random with no real plan for how the structure should work. (i used a div and a section as well as a bunch of classes to get to the result I ended with.

Community feedback

P

@Islandstone89

Posted

Hi there. I'll try to give you as best advice as I can :)

HTML:

  • Use appropriate semantic HTML landmarks whenever needed. Instead of adding role="main" to a <div>, you should use the <main> element, which has an implicit role="main". Every webpage needs a <main> that wraps all of the content, except for <header> and footer>. This is vital for accessibility, as it helps screen readers identify the "main" section of a page. Change .wrapper into a <main>.

  • You don't need to wrap the card content in a <section>, so I would remove it.

  • The alt text should be written naturally, so instead of qr-code you would write qr code. However, the alt text must also say where it leads(frontendmentor.io).

  • "Scan the QR code" should be a <p>, as it is not a heading but a paragraph.

  • Do not use <br> to force text onto a new line. The text should flow naturally, and all styling, including space between elements, should be done in the CSS.

CSS:

  • It's good practice to include a CSS Reset at the top.

  • text-align and font-familyare the same for all elements, hence they should be set on the <body>, and removed elsewhere - because of inheritance, the body's descendants will inherit the value.

  • font-size must never be in px. This is bad for accessibility, as it prevents the font size from scaling with the user's default setting in the browser. Use rem instead.

  • Paragraphs have a default value of font-weight: 400, so there is no need to declare it.

  • On the image, remove the margin-top. Add display: block and change the max-width to 100% - the max-width prevents it from overflowing its container.

  • To create the space between the image and the edge of the card, set padding on all 4 sides of the card.

  • Remove everything from .wrapper, except for background-color and border-radius. You shouldn't use position for layouts, and I'll show you a better way to center the card. Setting widths and heights in px is rarely a good idea, as components won't be able to adapt to different screens.

  • Do add a max-width of around 20rem on the card, to prevent it from getting too wide on larger screens.

  • To center the card horizontally and vertically, use Flexbox on the body:

display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
  • About media queries, there is no need for one on this challenge, because the design doesn't change. When you do need them, they should be in rem, not px. Also, it is common practice to do mobile styles first and use media queries for larger screens.

Marked as helpful

0

paradawx 40

@paradawx

Posted

@Islandstone89 thank you so much, this is better advice than I could have ever hoped for! I knew something was wrong with using px so much but i wasnt sure what the alternatives were. I'll update this file when I get a chance and keep those best practices in mind on my next few projects, thanks again!!

1

Please log in to post a comment

Log in with GitHub
Discord logo

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