Submitted almost 2 years ago
Product preview card component
@gregoriofrancisco99
Design comparison
SolutionDesign
Solution retrospective
Hello, guys! Here it is, my Product preview card component solution. I'd love to hear it from you on what I could do better. And, I'd like to know how do you guys do to present different images for desktop and for mobile. 😊
Thanks, right away
Community feedback
- @Osama-ElshimyPosted almost 2 years ago
Nice work!
Here is how you can toggle between the two images:
- Add both images to the HTML file:
<img class="desktop-img" src="images/image-product-desktop.jpg" alt="Product image" /> <img class="mobile-img" src="images/image-product-mobile.jpg" alt="Product image" />
In CSS:
.mobile-img { display: none; // Completely hides the image }
- Inside the media queries:
(max-width: 500px) { .desktop-img { display: none; // Hides desktop image } .mobile- img { display: block; // Displays mobile image } }
A few points you can improve:
- Every
a
element andimg
element should have analt
attribute that describes the image and what the link does. This is essential for screenreaders. You can add thealt
attribute like this:alt="YOUR TEXT"
I hope you find this helpful.
Happy Coding!
Marked as helpful1
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