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

Grid Layout w/ Flexbox for Product Card

Spencer Daniel•50
@WhaleMentalist
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


This is my first attempt. I made sure to add rounded corners in correct spots when resizing. The mobile mode does look a bit warped, BUT it does respond to smaller screen sizes. I ended up using 'srcset', which was pretty cool.

The font sizes might be a little off. Let me know if there is anything odd about the CSS, I tried to condense it. Also, just let me know in general what can improve, I am still pretty new at this.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Elaine•11,360
    @elaineleung
    Posted almost 3 years ago

    Hi Spencer Daniel, well done on this second challenge! I think you did many things well, and good job on using the picture element. It looks like you learned a lot in this challenge and also handled a lot of problem solving 🙂

    About the image being warped, what you can do is to use object-fit on the img selector. For the images in this challenge, I think you can just use object-fit: contain (which makes sure the whole image is viewed within the parent container and its width contained within the sides). I also would add display:block to the img container, but better yet is to add a reset rule at the top of your stylesheet for all images, like this:

    img,
    picture,
    video,
    canvas,
    svg {
      display: block;
      max-width: 100%;
    }
    

    Once you add the object-fit, you'll see the image shift, and there should be a lot of white space; to fix that and remove all the white space, remove grid-template-rows: 1fr 1fr; in the .product-card for that media query. I'd also change the media query breakpoint to something a bit higher, like 620px in both the CSS and picture element; since the width of your desktop component is 600px, you'd want a bit a white space before it switches.

    Lastly, I'd add margin:1rem to product-card so that in the mobile view the sides of the card wouldn't touch the browser sides.

    Great work here, and keep coding! 🙂

    Marked as helpful
  • Plinsinga•310
    @codedforfree
    Posted almost 3 years ago

    I think it looks quite good if you’re new to this. If I where you I would start by using some css variables for some of the basics like the fonts and colors.

    Also take a look at mobile styles. Maybe you can remove the grid styles and set it to block. Now you’re using grid to set a default behaviour.

    Keep up the good work 👍

    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
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