Design comparison
Solution retrospective
-
I didn't know how to change the product preview image automatically from mobile to desktop version, so I created a <img class="product-img"/> without the src attribute and used the content property in CSS to set the image, and used media query to change the image from mobile to the desktop version when needed. I've read that this isn't the best practice, are there any other alternatives?
-
I experimented a lot with widths and max-widths to get it the way it looks, not sure if this the best approach in regards to responsiveness.
-
Any best coding practices I should improve on? or Any mistakes in the way I approached the challenge (e.g. used wrong flex-box properties.... etc.)?
Thanks in advance (:
Community feedback
- @elaineleungPosted over 2 years ago
Hi Sai, I think you did a really great job here, especially as this is your first FEM challenge. I also just completed this challenge, and I wanted to reply to the point you made about changing images between mobile and desktop views:
While I think your workaround solution using
content: ""
was pretty clever, you'll see in your report that there's an issue with accessibility, namely regarding your<img>
not having a source image. What you can do instead is to usebackground-image:
. To do that, first replace your<img>
in the HTML with an empty<div>
along with a class for the image:<div class="preview-img"></div>
And in then in your CSS, add this:
.preview-img { background-image: url("./images/image-product-mobile.jpg"); background-size: cover; background-repeat: no-repeat; height: 15rem; // this is just what I used, feel free to experiment! }
Then add a media query to change the image to the desktop version:
@media (min-width: 750px) { background-image: url("./images/image-product-desktop.jpg"); height: 100%; }
Hope this helps, and welcome to Frontend Mentor!
Marked as helpful1 - @pradeeps4iniPosted over 2 years ago
Hi, Sal.
-
You can use <picture> element to change the different sized same image respective to the width of the viewport.
-
You can create utility classes for the properties that you use o multiple elements. For example:
.flex { display: flex; }
Now, you can use class="flex", on elements where you want to use flexbox.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