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

repsonsive product card using CSS Flexbox

Kalab Sisay•10
@KalabSisaySE
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I had always struggled with responsive design. In this project, and I've had to add a lot of media queries to fix things up. I'm curious to know how other developers manage responsive design. What is your thought process?

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • hitmorecode•7,540
    @hitmorecode
    Posted almost 2 years ago

    In general your page looks good. I see you used three media queries. You could have done it with just one

    • When creating a page, go with mobile first approach. This is actually the default setup of a page.
    • When you have a class inside another class, you don't have to write it like that in css. For example you have class .previous-price and it's inside .product-price, you don't have to do it like this
    .product-price .previous-price {
      font-family: 0.2em;
      text-decoration: line-through;
      color: var(--color-dark-grayish-blue);
    }
    
    ## You could have done it like this, because previous-price is your target and css knows where it is.
    .previous-price {
      font-family: 0.2em;
      text-decoration: line-through;
      color: var(--color-dark-grayish-blue);
    }
    

    If you have something like this

    <div class="main">
      <p>Lorem ipsum lorem ipsum</p>
    </div>
    
    <div class="second-main">
      <p>Lorem ipsum lorem ipsum</p>
    </div>
    

    Because the p tags have no class and if you want to target a specific p tag, you cannot tell css to target a p, it will target all p tags. In this case you can do it like this

    .main p {
      color: green;
    }
    
    .second-main p {
      color: yellow;
    }
    

    If you give a p tag a class or id, then you can just target that class or id

    You usde margin to place the card in the middle of the page, you don't have to user margin, use flexbox or grid.

    ## Lines that are commented out can be removed.
    body {
    /*   padding-inline: 1rem; */
      display: flex; /* add these lines */
      min-height: 100vh;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    .product-card {
      max-width: 65rem;
      height: 45rem;
      /* aspect-ratio: 4 / 3; */
    /*   margin: 6rem auto 2rem; */
      background-color: var(--color-white);
      box-shadow: 2px 2px 5px gray;
      display: flex;
      border-radius: 1rem;
      overflow: hidden;
    }
    
    Marked as helpful
  • Jennifer Souza•340
    @zoedarkweather
    Posted almost 2 years ago

    Hi, looks pretty good overall. I agree with the above comment that mobile-first is the way! I'd also point out you can use the picture element in your html to switch out the image for the correct screen size. Here's the mdn reference page on that if it might help: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture. Best!

    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