Blog preview card in HTML and CSS with Flexbox and Media queries
Design comparison
Solution retrospective
Proud of making markup and styling nearly as precise as in design
What challenges did you encounter, and how did you overcome them?None
What specific areas of your project would you like help with?None
Community feedback
- @Islandstone89Posted 8 months 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 the "main" section of a page. Replace<section>
with<div class="card">
, and wrap that in a<main>
. -
Do not use "image" in the alt text, as that will make screen readers announce "image" twice.
-
"Learning" is not a
<button>
, as it doesn't trigger an action. Make it a<p>
. -
Headings should always be in order, so you should never start with a
<h5>
. And "Published" is not a heading, so make it a<p>
. Also, wrap the date in a<time>
tag, like this:<p>Published <time datetime="2023-12-21">21 Dec 2023</time></p>
.Read more about the<time>
element here. -
Change the profile image alt text to "Headshot of Gary Hooper" - this is more descriptive than just "Avatar".
-
"Greg Hooper" is a
<p>
, not a heading. If it were a heading, it would be a<h2>
, as I mentioned the heading hierarchy above. -
.attribution
should be a<footer>
, and you should use<p>
for the text inside.
CSS:
-
Your CSS Reset is missing essential rules like
max-width: 100%
on<img>
, to prevent images from overflowing their container. I like to use the reset from Andy Bell. -
Add around
1rem
ofpadding
on thebody
, so the card doesn't touch the edges on small screens. -
Remove the margin on the card.
-
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: 100svh;
-
Remove width and height on "Learning". Give it a
display: inline-block
and somepadding
. -
max-width
on card should be in rem. -
Remove the width and height on the card. Never limit the height of elements containing text!
-
Use
1.5
forline-height
instead of150%
. You can set it onbody
, and the elements will inherit the value, there's no need to declare it on every element. -
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. -
Media queries must be in rem, and it is common to do mobile styles as the default.
Marked as helpful0 -
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