I am using responsive images by srcset
and sizes
attributes in <img>
.
I have 3 images with 3 different sizes (200x200, 400x400, 600x600). I need to switch them for different sizes of viewport as follows:
viewport size 1190px -> image size 555px
viewport size 991px -> image size 300px
viewport size 575px -> image size 130px
Any other viewport size -> image size 255px
to do this I coded as follows:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>responsive test</title>
</head>
<body>
<img src="Go-400_x_400.jpg"
srcset="Go-200_x_200.jpg 200w,
Go-400_x_400.jpg 400w,
Go-600_x_600.jpg 600w"
sizes=" (max-width:575px) 131px,
(max-width:991px) 300px,
(max-width:1199px) 555px,
255px"
alt="responsivetest" >
</body>
</html>
As the definition, for different sizes, media query should select the appropriate image from srcset for each size. I expect 200x200 image for max-width:575px size, 400x400 image for max-width:991px size and 600x600 image for max-width:1191px size. But for all sizes only the 600x600 image will be loaded and no shifting images. How I solve this?