Design comparison
Solution retrospective
Hello guys, I'm currently learning javascript.
Any kind of feedbacks are Welcome😀.
Can someone tell me, how can i change my "img src value" at different media queries?😕
Community feedback
- @LukaKobaidzePosted almost 3 years ago
Hello!
To change image on different media queries, you can use
picture
tag.<picture> <source srcset="image-mobile.png" media="(max-width: 375px)"> <img src="image-desktop.png" alt="Image" > </picture>
As you can see in the code, i wrote
source
andimg
tags inside picture.media
attribute is just like how you write CSS media queries. If viewport width is less than or equal 375px, thenimage-mobile.png
is going to apply, and if not, thenimage-desktop.png
applies. You can also write more than onesource
with different media queries.Check out this source, It's about responsive images.
Hope this is helpful xD
Marked as helpful2@Illyaas4ShowPosted over 2 years ago@LukaKobaidze Can I also use a div and change the
background-image: url() ;
at different media queries?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