Product preview card component using responsive image elements

Solution retrospective
- Use the `` element to create responsive images. It allowed me to dynamically load the correct image based on the viewport size.
- Use CSS Local fonts
- Use
element::before
selector and thecontent: url()
property to set the shopping cart icon. Bonus: It automatically sets the image to the appropriate size!
object-fit
property needs a set width and height on the element. I had a situation where the image container was shorter than the adjacent info container. I solved it by setting the height to 100% with object-fit: cover
. The width was already set at 100%.
When the viewport hits the breakpoint, sometimes I see a flicker as the browser tries to change the picture from mobile to desktop and vice-versa. I'm not sure what's the reason and how to fix it.
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@PetterTSaatvedt
Great work Sayed! The solution aligns well with the provided design, and functions well on all screen sizes :)
Your code is neatly structured which makes it easy to read and understand, while supporting maintainability of the code! I'm not seeing much that could be improved, to be honest, so well done!
As for the flicker you mentioned upon changing images, I assume this is simply due to the fact that the browser needs to load the other picture every time there is a change in layout. I would assume this could be fixed through caching of the images, so that they are already available when needed, however this would demand some JavaScript, which isn't necessary for this particular project :)
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