Design comparison
Solution retrospective
having trouble centering the div containing all the content on the page. Figured out the left and right margin but can't get top or bottom.
Community feedback
- @Islandstone89Posted 2 months ago
HTML:
-
Remove
role="contentinfo"
- this is the implicit role for a<footer>
element, which you don't have. -
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" section. Wrap the card in a<main>
. -
The alt text should be written naturally, without using
-
between the words. Write something short and descriptive, without including words like "image" or "photo". 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." -
I would change the heading to 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.
CSS:
-
Including a CSS Reset at the top is good practice.
-
Use the style guide to find the correct
font-family
, and remember to specify a fallback font:font-family: 'Outfit',sans-serif;
-
I like to add
1rem
ofpadding
on thebody
, to ensure the card doesn't touch the edges on small screens. -
Remove all positioning and transform properties.
-
On the
body
, removeheight
. -
To center the card horizontally and vertically, I would use Flexbox on the body:
display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 100svh;
-
Remove all widths in
%
. -
max-width
on the card must be in rem. I would set it to around20rem
. -
font-family
should be set on thebody
, and removed elsewhere. The children of thebody
will inherit the font from their parent. -
letter-spacing
must not be inpx
. You can useem
, where1em
equals the element's font size. -
I like to add
text-wrap: balance
on headings - this ensures, as per MDN, that "text is wrapped in a way that best balances the number of characters on each line". -
On the image, add
display: block
andmax-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.
Marked as helpful0@bakellianPosted 2 months ago@Islandstone89 thank you so much! extremely helpful
1 -
- @MikDra1Posted 2 months ago
To make the image the size that you want I encourage you to use this technique to make the card responsive with ease:
.card { width: 90%; max-width: 600px; }
On the smaller screens card will be 90% of the parent (here body), but as soon as the card will be 600px it will lock with this size.
Also to put the card in the center I advise you to use this code snippet:
.container { display: grid; place-items: center; }
Hope you found this comment helpful 💗💗💗
Good job and keep going 😁😊😉
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