Design comparison
Solution retrospective
Nothing
What challenges did you encounter, and how did you overcome them?To change product image from desktop mode to mobile mode, I use "background-image".
What specific areas of your project would you like help with?Is there another way to change the image? I'm having trouble getting the links to display properly on GitHub. How to address so that images and fonts are loaded correctly in the live view? That is a big problem for me.
Community feedback
- @slackwareePosted 6 months ago
Hi, are you having trouble with changing the image when a certain viewport width is met? A simple way of doing this is by giving each
img
element an id, respective of their use case. Then in your CSS file, hide one of the elements usingdisplay: none
, and create a media query to display that image when the viewport width is met. Also, make sure to hide the other image. Example:HTML:
<img src="image/source" id="perfume-image-mobile"> <img src="image/source" id="perfume-image-desktop">
CSS:
#perfume-image-desktop {display:none} @media only screen and (min-width: 769px) { /* Desktop styles */ #perfume-image-mobile {display:none;} #perfume-image-desktop {display:/*block/grid/flex*/} }
1
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