Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Product preview card component

Robson Gomes•20
@robsongomes
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Lucas 👾•104,160
    @correlucas
    Posted almost 3 years ago

    👾Oi @robsongomes, tudo bem? Parabéns pelo desafio! Seja bem vindo a comunidade do Frontend Mentor

    Acabei de ver sua solução e tenho umas dicas pra melhorar seu código/design:

    A sua solução ficou muito boa, a estrutura html o design também, algo que você pode fazer para melhorar a imagem que precisa mudar entre mobile e desktop é usar <picture> ao invés de <img> dentro de uma div. Por motivos de SEO e mecanismos de pesquisa tipo Google e bing, não é uma boa prática importar esta imagem do produto com CSS, pois isso dificultará a localização da imagem no google. Você pode gerenciar ambas as imagens dentro da tag <picture> e usar o código html para definir quando as imagens devem mudar configurando o dispositivo max-width dependendo do dispositivo (mobile / desktop) Aqui está um guia sobre como usar picture: https://www.w3schools.com/tags/tag_picture.asp

    Veja o exemplo abaixo:

    <picture>
      <source media="(max-width:650px)" srcset="./images/image-product-mobile.jpg">
      <img src="./images/image-product-desktop.jpg" alt="Gabrielle Parfum" style="width:auto;">
    </picture>
    

    👋 Espero que essas dicas te ajudem e que você continue no foco!

    Marked as helpful
  • Account deletedPosted almost 3 years ago

    Hey @robsongomes, some suggestions to improve you code:

    • Implement a Mobile First approach 📱 > 🖥

    With mobile devices being the predominant way that people view websites/content. It is more crucial than ever to ensure that your website/content looks presentable on all mobile devices. To achieve this, you start building your website/content for smaller screen first and then adjust your content for larger screens.

    • Change the width of your component container to max-width to make it responsive.

    • The button's hover color is incorrect. Currently, it is a dark blue, when it should instead be a dark green.

    • Your price is missing the dollar sign.

    Happy Coding! 👻🎃

    Marked as helpful
  • Melvin Aguilar 🧑🏻‍💻•61,020
    @MelvinAguilar
    Posted almost 3 years ago

    Hi @robsongomes 👋, good job for completing this challenge and welcome to the Frontend Mentor Community! 🎉

    This is a good solution for this challenge and here are some suggestions you might consider to improve accessibility:

    • You can use <picture> tag when you need to change the image on different viewports, using this tag will prevent the browser from loading both images, saving bandwidth. More information here

    Example:

    <picture>
       <source media="(max-width: 600px)" srcset="images/image-product-mobile.jpg">
       <img src="images/image-product-desktop.jpg" alt="your_alt_text" class="product-image">
    </picture>
    
    • You could use the <del> tag to display the old price:
    <del>
       <span class="sr-only">Old price: </span>$169.99
    </del>
    

    Note that I added the <span> with the sr-only class to the del element, this will provide more information about what your old price is about.

    The sr-only class is a class that you can add to hide content visually but is only visible to screen-readers:

    .sr-only {
      clip: rect(0 0 0 0); 
      clip-path: inset(50%);
      height: 1px;
      overflow: hidden;
      position: absolute;
      white-space: nowrap; 
      width: 1px;
    }
    

    More information here

    • The cart icon is for decoration purposes only, so it can be hidden from screen-readers by adding aria-hidden="true" and leaving its alt attribute empty:
    <img src="images/icon-cart.svg" alt aria-hidden="true">
    

    I hope those tips will help you.

    Good Job and happy coding !

    Marked as helpful

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

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