Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 2 years ago

Respinsive Product Preview Card using HTML and CSS

Petabyte•190
@peta-8-bit
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


If you look closely there is maybe 1px or 2px extra height for the card below the image which just has the background color white. Don't know why it happens or how to make the entire height of the card taken by the image. Please let me know if you can solve it.

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Fidel Lim•2,775
    @fidellim
    Posted over 2 years ago

    Hi @Petabyte,

    Congrats on finishing the project!

    To remove the white background color below your image, you could just set your image tag as a block.

    .image img {
        display: block;
        width: 300px;
        border-radius: 10px 0px 0px 10px;
    }
    

    The code above should fix that issue.

    If you are also interested in removing the warning on your accessibility report, you can add this block of code:

    <div class="attribution">
        Challenge by <a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>. 
        Coded by <a href="https://www.frontendmentor.io/profile/peta-8-bit">Petabyte</a>.
      </div>
    

    inside a <footer> tag.

    Let me know if it works!

    Marked as helpful
  • Amal Karim ✅•1,290
    @amalkarim
    Posted over 2 years ago

    Instead of using "picture" element like code below

    <div class="image">
      <picture>
        <source media="(max-width:600px)" srcset="image-product-mobile.jpg">
        <img src="image-product-desktop.jpg" alt="image of product">
      </picture>
    </div>
    

    Try this

    <div class="image">
      <img class="img-desktop" src="image-product-desktop.jpg" alt="image of product">
      <img class="img-mobile" src="image-product-mobile.jpg" alt="image of product">
    </div>
    

    Then in your css, give those two images styling that will show and hide them at the right condition

    .img-desktop {
      display: block;
    }
    .img-mobile {
      display: none;
    }
    
    @media screen and (max-width: 600px) {
      .img-desktop {
        display: none;
      }
      .img-mobile {
        display: block;
      }
    }
    

    Some advice: Give your "main" element min-height: 100vh; instead of height: 100vh;, to avoid some parts of the page hidden when the height of the page is taller than the browser (mainly in mobile view). I also recommend display: grid for "body" element, it could give you more flexible, simple, and robust layout. Read this article in Css Tricks to gain basic understanding about CSS Grid. Last but not least, wrap your <div class="attribution">...</div> inside <footer>...</footer> to get rid the warning message in Accessibility Report.

    Hope this helps!

    Marked as helpful
  • Frank Ruiz•410
    @fruizotero
    Posted over 2 years ago

    I think they already helped you with some solutions, but in case you want to try it some other way.

    The white space you see below the image is due to line-hieght.
    You can fix it by adding the following

    .card {
        line-height: 0;
    }
    
    .cardtext {
        line-height: normal;
    }
    

    Here you can read more about it
    line-height

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

Oops! 😬

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

Log in with GitHub