Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 7 months ago

Responsive Blog card using css variables and media queries

bem, accessibility
P
Kumani Kidd•170
@amancalledkidd
A solution to the Blog preview card challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

Utilising the css variables and media queries. Next time I will try to make variable selectors more efficent with less code. Also will focus on building mobile first in future

What challenges did you encounter, and how did you overcome them?

Using semantic elements to improve accessiblity. To help I looked at best pracices online

What specific areas of your project would you like help with?

Any image sizing tips?

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Huy Phan•3,430
    @huyphan2210
    Posted 7 months ago

    Hi, @amancalledkidd

    I would like to answer your question regarding image sizing.

    1. Your img's height doesn't fill its parent element

    You’re setting your img's width to 100%, making it match the width of its parent element (.blog-post-header). That works as expected.

    However, the img's height doesn’t fill the .blog-post-header. This happens because images are inline-replaced elements by default, meaning they behave like text characters. As a result, browsers leave extra space below the image, similar to how they leave space below letters like "g" or "p" in text.

    To fix this, you can set vertical-align: top on the img. This works because vertical-align adjusts how inline-replaced elements align relative to the text baseline. By setting vertical-align: top, you align the image to the top of its container, removing the unwanted space below it.

    1. Use the picture Element with source and img

    This challenge has a quite straightforward solution. However, you might face more complex challenges that require better image handling. In such cases, consider using the picture element to serve different images based on viewport size.

    <picture>
      <source srcset="image-large.jpg" media="(min-width: 768px)">
      <source srcset="image-medium.jpg" media="(min-width: 480px)">
      <img src="image-small.jpg" alt="Responsive example image">
    </picture>
    

    How It Works:

    • The browser checks each <source> element from top to bottom.
    • It uses the first srcset that matches the viewport's media query.
    • If none match, the <img> element serves as a fallback.
    Marked as helpful
  • P
    Kumani Kidd•170
    @amancalledkidd
    Posted 7 months ago

    Thank you very much @huyphan2210. This advice is really helpful! I had no idea there was a picture element, will be putting this into practice on the next challenge - Thank you again!

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub