Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Product Preview Card

Cody Tesslerβ€’ 40

@cjtessler

Desktop design screenshot for the Product preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Community feedback

@MelvinAguilar

Posted

Hello πŸ‘‹. Congratulation on successfully completing your first challenge πŸŽ‰ ! !

I have other recommendations regarding your code that I believe will be of great interest to you.

HTML πŸ“„:

  • You could use the <del> tag to indicate the price that was before the discount. It is typically displayed with a line through the text, indicating that it has been removed. Additionally, you can use a sr-only class to describe the discount. This will help screen reader users to understand that the price was discounted.

    Example: <del><span class="sr-only">Old price: </span>$169.99</del>

  • The alt attribute is used to provide a text description of the image which is useful for screen reader users, assistive technology users, and search engine optimization. Add the alt attribute to the <img> tag of the product.

CSS 🎨:

  • You should use the cursor: pointer property to indicate that the element like a button or a link is clickable.
  • I currently have two issues with your solution: the image is not perfectly distributed on desktop computers, and the solution is cut off on mobile devices.

    I have the following suggestions to fix these problems:

  • The best way to create two columns in CSS is to use the grid layout πŸ“. Using the grid layout, you can create two columns by setting the display property of the parent element to grid and then defining the number of columns you want with the grid-template-columns property.
  • Setting a defined height for the card component is not recommended. The content should define the component height, otherwise, it will not be allowed to extend beyond your specifications. Alternatively, you can use min-height.

    result:

    .card-container {
        display: grid;
        grid-template-columns: 1fr 1fr; /* NOTE: Using grid layout to create two columns */
        max-width: 600px;
        min-height: 450px; /* NOTE:  use min-height instead of max-height */
        background-color: hsl(0, 0%, 100%);
        margin: 2rem;
        border-radius: 1rem;
        overflow: hidden;
    }
    
    img {
        /* max-height: 100%; */
        /*  NOTE: This makes the image fit the component regardless of size. */
        height: 100%; 
        width: 100%;
        display: block;
    }
    
    @media only screen and (max-width: 600px)
    .card-container {
        /* display: flex; */
        /* flex-direction: column; */
        /* margin: 5%; */
        /* max-height: 75%; */
        grid-template-columns: 1fr;
    }
    

I hope you find it useful! πŸ˜„ Above all, the solution you submitted is great!

Happy coding!

Marked as helpful

1

Cody Tesslerβ€’ 40

@cjtessler

Posted

@MelvinAguilar Thank you! The comments about height were helpful! I pushed a fix for the mobile design based on your feedback.

I have more practice with flex, so I tend to default to it. But - I can see why grid would be a cleaner choice here.

0
Hassia Issahβ€’ 50,650

@Hassiai

Posted

There is no need to give the body a width value. To center .card-container on the page using flexbox, replace the height in the body with min-height:100vh.

Use relative units like rem or em as unit for the padding, margin, width values and preferably rem for the font-size values, instead of using px which is an absolute unit. For more on CSS units Click here

There is no need to give .card-container a height value, the padding value of .info-container will replace it and it is a responsive replacement.

Hope am helpful.

Well done for completing this challenge. HAPPY CODING

Marked as helpful

1

Cody Tesslerβ€’ 40

@cjtessler

Posted

@Hassiai Thank you! The first comment was helpful in my understanding of height vs min-height, and the second comment reminded me about units. I was too focused on being pixel-perfect to the point I measured using PowerToys.

I am unsure about the third recommendation. If I remove the height from .card-container, then the image stretches to the fill height. Adjusting the padding on .info-container doesn't seem to help.

I pushed the recommended changes to GitHub.

Thanks again!

0

Please log in to post a comment

Log in with GitHub
Discord logo

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