How can I change image based on screen size? #next/image
Answered
Netherland Dwarf posted this in #help-forum
Netherland DwarfOP
I've tried the srcSet attribute but it can't be used in Next.Js , I want to use a different background image in mobile, tablet and desktop view.
27 Replies
@Netherland Dwarf In native image tag, we have srcset to have different sized images(responsive images) and also totally different images for different dimensions.
However in next.js for responsive image, they have
The only way to do that is just conditional rendering @Netherland Dwarf
However in next.js for responsive image, they have
sizes property - but I don't think this allows us to have different images.The only way to do that is just conditional rendering @Netherland Dwarf
Netherland DwarfOP
Thank you @James4u I will give it a try.
yeah, so using multiple image tags and use
display:hiddenAnswer
@James4u yeah, so using multiple image tags and use `display:hidden`
Netherland DwarfOP
it worked thank you very much
Original message was deleted
happy to help you! mark solution please π
Netherland DwarfOP
This is the solution. Need to optimize to be dry but it works.
Original message was deleted
yeah, it looks okay. I only meant marking an answer as a solution
π
Netherland DwarfOP
oh haha. Got it
and also, you are using totally different images - not only the size, right?
@James4u and also, you are using totally different images - not only the size, right?
Netherland DwarfOP
yes the 3 images are different optimized each one for better quality.
can you show me those three images if you don't mind?
is it just the quality & size or totally different images? like π» in the desktop and π° in the tablet and π in the mobile lol
@James4u can you show me those three images if you don't mind?
Netherland DwarfOP
correct it's just the quality and size sending in a minute
omg, then you should use
sizes property @Netherland DwarfNetherland DwarfOP
will it automatically know the images I need?
yeah, they automatically generate small sized optimized images!
check out the docs and video I shared
Netherland DwarfOP
okay ,I will check it out
Netherland DwarfOP
I tried using the sizes attribute but for some reason it's not pulling the images for tablet and desktop size? What might I be doing wrong?
you are using mobileHomeBg - which is the smallest I believe
you should provide desktopHomeBg
Netherland DwarfOP
These 3 images are in the home folder. Should the src just be the home and then it will pick the photo??