Design comparison
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
- @Islandstone89Posted 10 months ago
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 implicitrole="main"
. Every webpage needs a<main>
that wraps all of the content, except for<header>
andfooter>
. 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 writeqr 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
andfont-family
are 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
. Adddisplay: block
and change themax-width
to100%
- 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 forbackground-color
andborder-radius
. You shouldn't useposition
for layouts, and I'll show you a better way to center the card. Setting widths and heights inpx
is rarely a good idea, as components won't be able to adapt to different screens. -
Do add a
max-width
of around20rem
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 helpful0@paradawxPosted 10 months ago@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 GitHubJoin 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