Product preview card component

Solution retrospective
I don't know how to resize the white box, whenever I try to resize it, it will push the words down. I don't think my code is practical, I just try to find a way to make it look like a design. I have not learned grid yet, may be that is the reason I can not organize my layout? What should I learn to organize the box more easier?
Please log in to post a comment
Log in with GitHubCommunity feedback
- @mikej321
Hello there, and great first try!
One thing I may suggest is to learn CSS Grid as that would solve most of the problems that you are having with resizing. For now, I'd suggest setting a display of grid to your .main class and going from there. With Grid, you have to define the columns for this project, and it uses 2 columns. You can set a grid-template-columns of 1fr 1fr, grid-template-rows of auto 1fr, and then set your image for the desktop version to grid-row: 1 / 4, which should cause the image to span the entirety of the first column. I'd also recommend using responsive units for size as setting explicit widths would cause non-responsive areas. I'm also new so I apologize if my answer is badly worded :( I hope I helped and if you need any help, I can definitely try!
Marked as helpful - @correlucas
👾Hello @Lucas760, Congratulations on completing this challenge!
Your solution its almost done and I’ve some tips to help you to improve it:
Use the THE PICTURE TAG that is a shortcut to deal with the multiple images in this challenge. So you can use the
<picture>
tag instead of importing this as an<img>
or using a div withbackground-image
. Use it to place the images and make the change between mobile and desktop, instead of using adiv
orimg
and set the change in the css withdisplay: none
with the tag picture is more practical and easy. Note that for SEO / search engine reasons isn’t a better practice import this product image with CSS since this will make it harder to the image. Manage both images inside the<picture>
tag and use the html to code to set when the images should change setting the devicemax-width
depending of the device desktop + mobile.Check the link for the official documentation for
<picture>
in W3 SCHOOLS:https://www.w3schools.com/tags/tag_picture.asp
See the example below:
<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>
👨💻Here's my solution for this challenge if you wants to see how I build it: https://www.frontendmentor.io/solutions/product-preview-card-vanilla-css-and-custom-hover-state-on-hero-85A1JsueD1
✌️ I hope this helps you and happy coding!
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