Alright, Ive worked in html for a while but now attempting to build a fully responsive site with responsive images/changes according to device. I need this for a client and was going to do with media calls in CSS but found a tutorial on srcset claiming it is the correct way to accomplish this.
My person has specified they want a separate image to load for the following: - desktop -iphone 6s -iphone 6plus/ipad pro -other/smaller mobile
My image has a margin of 20 px on each side, meaning I need the image to be the width of the screen - 40px.
I went to https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions and followed a tutorial on src set and came up with these sizes, taking into account when to multiply by 2 or 3 for resolution (I think I have gotten a handle on how pixels/resolution works):
- Desktop: 768px
- iphone 6s: 670px
- iphone 6 plus:1122px
- other mobile: 240px
I then wrote the following having read the browser will switch to the correct image based on screen size:
<img src="/images/home-desktop.jpg" srcset="/images/home-iphone6s.jpg 670w, /images/iphone6plus.jpg 1122w, /images/allMobile.jpg, 240w, /images/home-desktop.jpg 768w">
however nothing at all is working, no matter how I stretch the browser.I get this:
What am I doing wrong here? the values with the w are the sizes of the images - this isn't supposed to be screen size right? how can I fix this?