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

Responsive Product Preview Component - CSS Grid, Flexbox, Mobile First

P
TheWraithDev•70
@TheWraithDev
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 did an entire mobile first approach trying to ensure everything was consistent and focused on accessibility aswell as a responsive layout.

I also focused on the CSS to make sure it was structured and appropriate

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

None - my biggest area I ran into was a bug with the scaling of my layout but it was a typo that caused it

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

Responsiveness & Accessibility Best practice guidance where possible as I am always wanting to improve

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Grace•32,130
    @grace-snow
    Posted 9 months ago

    I hope this is helpful

    • you should be using the picture element to serve the main card images. The mobile as the default and the large screen one in the source tag with a min-width media query. This is much better for performance.
    • the alt text should describe distinctive features of the image. There is no benefit to it if it just repeats the product name that's in the heading anyway.
    • don't capitalise text in html. Let css do that. Its a styling comcern not a content concern.
    • this kind of product card would never be used to serve the main heading on a page. So you know it shouldn't have a h1. Use a lower importance heading level like h2 instead.
    • strike through text isn't consistently announced to screen readers. I recommend you include some sr-only text in a span to make it clear that is the old price.
    • there are extra divs inside the text area of the card that seem unnecessary. I'm not sure why the price one includes the button or why theres one wrapping the heading and paragraph. Or why theres an extra span wrapping the button icon.
    • I would expect this card to have two divs inside. One for the image (picture element) and one for the text content. Making the image itself into the flex/grid child isn't as robust. Think of it as one set of elements for the layout, then the image or text are the content that gets placed into that layout. If an author ever swaps out that content for some new content, nothing should break. It's a general principle to consider rather than a "failure" - the best practice would be to place the image inside the component layout not make it be part of the layout. I hope that explains it.
    • you don't need all those css custom properties for font families on each element. That's not at all how you should be using variables like this. Just set the font family on the body. That's what's used for most elements and they will inherit from the body. Then set it for headings as base styles (or on the class for the heading). In a real project, sensible base styles are usually set on element selectors straight after the reset. At the most yoh need two css custom properties for font family: heading and body.
    • not for this challenge, just general learning: Custom properties are for values that will be reused a lot. And often custom property values themselves will change. That's where there value really comes — like setting a --heading-color property might be set to two different colour values depending on whether it's inside a dark theme or light theme selector.
    • either the body or main need a min-height 100svh.
    • I'm not sure why both body and main are flex columns... That seems unusual, possibly unnecessary (note I am only reading the code not at my computer so unable to inspect which may make the reason clearer).
    • I would expect the main to have padding not margin. It's not wrong but is an unusual choice. If the purpose is to prevent its content from hitting its edges it should be padding.
    • border radius can go on the card with overflow hidden to crop out the overflowing child corners. There's no need to set border radius on the card components child elements which then have to change at each screen size. More work for no benefit.
    • the text part of the card should have padding on all sides. Don't over complicate it.
    • it's fine to use flex for this component, but it would be shorter/easier to use grid. Because by default (mobile) grid stacks vertically, then the only change needed on larger screens is defining two template columns of 1fr.
    • for the pricing part it would make more sense to use flex there (as the layout only needs to be along one axis) and include flex-wrap for the rare occasions where large text sizes/small devices may cause the content to need to wrap. The button doesn't need to be in that container. It's just a full width button, separate content. Adding it into the price container is over complicating.
    • don't set border none on buttons. Leave at least a transparent border (or the same colour as the background). High contrast themes rely on buttons having borders to be able to style them correctly (accessibility issue).
    • of the button is flex use the gap property on it don't set directional margins to create space between it's children. Eg gap: 1ch.
    • the text side of the card doesn't need different styling between mobile and desktop. It looks like only the padding needs to change a little.
    Marked as helpful
  • zzdevs•130
    @zzdevs
    Posted 9 months ago

    you can use the clamp function in css to scale up the font size in higher widths for a better user experience.

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.

Frontend Mentor for Teams

Frontend Mentor for Teams helps companies and schools onboard and train developers through project-based learning. Our industry-standard projects give developers hands-on experience tackling real coding problems, helping them master their craft.

If you work in a company or are a student in a coding school, feel free to share Frontend Mentor for Teams with your manager or instructor, as they may use it to help with your coding education.

Learn more

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