Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 1 year ago

Responsive product preview card

anisbeny•120
@anisbeny
A solution to the Product preview card component 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?

I'm proud of the result

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

nothing to report

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

nothing to report

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • anisbeny•120
    @anisbeny
    Posted about 1 year ago

    Thank you for your feedback, I really appreciate your recommendations.

  • David Dutra•230
    @dvdgd
    Posted about 1 year ago

    Hello! You've done a great job—it's nearly perfect.

    I just have a few points to cover to help you improve it even further:

    • While viewing on a mobile screen, I noticed that the image source doesn't change. You can fix this by replacing the figure with a picture and adding different sources with breakpoints. Here's an example:

      <picture>
        <source media="(min-width: 768px)" srcset="./images/image-product-desktop.jpg">
        <img src="./images/image-product-mobile.jpg" alt="Perfume bottle">
      </picture>
      

      When using picture, ensure to set the display property to contents: display: contents.

      • By default, the <picture> element behaves like a block-level element, meaning it takes up the full width of its parent container. However, the <img> element inside it behaves like an inline-level element. This means that any padding, margins, or borders applied to the <picture> element will affect its layout, potentially causing unintended spacing or alignment issues.

      • Setting the display property of the <picture> element to contents alters its behavior. The contents value causes the <picture> element to behave as if it were not there in terms of layout, essentially making its children (in this case, the <source> and <img> elements) direct children of the <picture> element's parent. This ensures that any styles applied to the <picture> element itself do not interfere with the layout of its children.

    • I noticed that the card grows on mobile but doesn't shrink less than 350px due to your clamp(350px, 75%, 750px). Here's how to address this:

      • Remove the clamp for the min-width of the article.
      • Add a max-width of 350px for the card on devices with screens smaller than or equal to 768px. This way, you'll only need to consider two variations: desktop and mobile. This ensures the card doesn't grow excessively but can still shrink for very small screens.
    • For your price, you could add flex-wrap: wrap. This will prevent the price from overflowing on small screens.

    TIP: For desktop, the max-width of the card could be 600px, and for mobile devices 350px. This could simplify centering the card using flex-box.

    PLUS: There are several ways to center an element on the page. But instead of using position and transform, you could utilize flex-box, where it remains a cleaner way and helps us deal with responsiveness, and I saw you already know how it works. Here's an example::

    body {
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100svh; /* Ensure your page occupies all available height */
    }
    

    I hope this feedback helps you improve your solution. Feel free to ask anything, and if you'd like, I can create a PR on GitHub to assist you further!

    I appreciate how you've made your HTML semantic and opted for CSS selectors instead of creating classes—awesome!

    Keep up the good work and happy coding!

  • homciAbdallah•210
    @homciAbdallah
    Posted about 1 year ago

    Does the solution include semantic HTML? Yes in deed Is it accessible, and what improvements can be made? Can and improvements in size Does the design look good on a range of screen sizes? Yes Is the code well structured, readable, and reusable? Yes Is the solution significantly different from the design? a little

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