
Design comparison
Solution retrospective
I like the fact that i coded it pretty fast, from what i've used to do before. I would like to be even faster next time.
What challenges did you encounter, and how did you overcome them?using width
broke my flexbox at a certain point i don't really know why.
the html part, and using flexbox to make the overall structure.
Community feedback
- P@Islandstone89Posted about 1 month ago
HTML:
-
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 a page's "main" content. Wrap the card in a<main>
. -
There is no need to wrap the image in a
<div>
. -
Don't use IDs for styling. Instead, give elements a class, and use that as the selector. This article explains when to use the
id
attribute. -
You don't need to include words like "image" or "photo" in the alt text. Screen readers start announcing images with "image", so an alt text of "image of qr code" would be read like this: "image, image of qr code". The alt text must also say where it leads(the frontendmentor website). A good alt text would be "QR code leading to the Frontend Mentor website."
-
"Improve your front-end skills by building projects" is a heading. I would make it a
<h2>
- a page should only have one<h1>
, reserved for the main heading. As this is a card heading, it would likely not be the main heading on a page with several components. -
Change
.attribution
to a<footer>
, and use<p>
for the text inside.
CSS:
-
Make a habit of including a modern CSS Reset at the top of the stylesheet.
-
I recommend adding a bit of
padding
, for example16px
, on thebody
, to ensure the card doesn't touch the edges on small screens. -
Move
font-family
tobody
, and remember to specify fallback fonts, in case the font doesn't load on the user's device:font-family: 'Outfit', system-ui, sans-serif;
-
Remove all positioning and transform properties, they should not be used for layouts like this.
-
To center the card horizontally and vertically, with some space between the
<main>
and the<footer>
, I would use Flexbox on the body:
display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 100svh; gap: 1rem;
-
Remove the
width
inpx
on the card. We rarely want to give a component a fixed size, as we need it to grow and shrink according to the screen size. -
We do want to limit the width of the card, so it doesn't get too wide on larger screens. To solve this issue, give the card a
max-width
of around20rem
. -
font-size
must never be in px. This is a big accessibility issue, as it prevents the font size from scaling with the user's default setting in the browser. Use rem instead. -
Since all of the text should be centered, you only need to set
text-align: center
on the body, and remove it elsewhere. The children will inherit the value. -
Paragraphs have a default value of
font-weight: 400
, so there is no need to declare it. -
On the image, add
display: block
,height: auto
and changewidth
tomax-width: 100%
- the max-width prevents it from overflowing its container. Without this, an image would overflow if its intrinsic size is wider than the container.max-width: 100%
makes the image shrink to fit inside its container.
0 -
- @BeatrizBastosBorgesPosted about 1 month ago
Great job on your layout! Your code is well-structured, and using
transform: translate()
for centering is a smart approach.Regarding the issue where
width
breaks your Flexbox at a certain point, this might be happening becausewidth: 100%
inside an absolutely positioned container can cause unexpected behavior.Possible Solutions:
- Replace
width: 100%
withmax-width: 100%
for elements inside#main
. This prevents them from overflowing their container. - Instead of position: absolute on
#main
, try usingdisplay: flex
on thebody
withheight: 100vh
; for better alignment behavior. - If
.attribution
should stay at the bottom without affecting the layout, consider usingposition: relative; margin-top: auto;
instead.
Hope this helps!
0 - Replace
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