Design comparison
Solution retrospective
Built in React with some simple functionality. The component renders content based on props. There is logic to render and style the correct price, whether or not the product is full price or on sale, as well as a button that tracks product available in state and will disable when the available quantity reaches 0.
I wanted to find a solution to render the product images responsively that didn't rely on CSS, since background images don't support alt attributes. I used the <picture> element, which caused some issues with how the image scaled to fill the parent container, and took some time to address. Are there better ways to handle making sure the component meets accessibility guidelines?
Community feedback
- @elaineleungPosted about 2 years ago
Hi DJ Drakos, great work here, and I like how you included the "extras" in your solution, which I managed to test somewhat when I was clicking on the "add product to card" button (by the way, on that note, you can add a
cursor: pointer
to show users that the element is interactive).About your question regarding the image, I think what you did in using
picture
is the right way to go instead of usingbackground-image
. In terms of scaling, just looking at your CSS in the inspector, you probably just need to addobject-fit
to theimg
(I'd probably useobject-fit: contain
at mobile view andobject-fit: cover
at desktop view). Often times, not havingobject-fit
would result in the image being distorted and out of its aspect ratio, and if that's the case then the issue is not so much about using thepicture
element or not. I'm guessing the scaling issue could be a reason why your component is not responsive right now, as you could be trying to prevent it from getting distorted.Anyway, I hope you get it sorted, and once again, great job! 😊
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin 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