why is srcset not working?

独自空忆成欢 提交于 2019-12-11 02:22:01

问题


So i have this code:

<html>
<head>
</head>
<body>

<img src="small.jpg" srcset="https://media.kulturbanause.de/blog/2014/09/responsive-images/small.jpg 320w, https://media.kulturbanause.de/blog/2014/09/responsive-images/medium.jpg 600w, https://media.kulturbanause.de/blog/2014/09/responsive-images/large.jpg 900w" alt="">

</html>

According to the code, there should be a diffrent image be loaded for diffrent viewport sizes. however when I run this code on my phone, it still shows the large.jpg even for 320w (viewport width) the small one should be loaded.


回答1:


According to the code, there should be a diffrent image be loaded for diffrent viewport sizes.

You've misunderstood how [srcset] works. [srcset] allows you to suggest a series of different sources for a device to use and give the device the option to pick an image that's likely to be optimal for the device.

The purpose is to save bandwidth, so devices typically download the largest image that would reasonably fit on their screens, although there are a lot of other nuances that come in to play that I'm not going to get into here.

What devices are not going to do is switch between the various images when a different breakpoint would apply. This is the job of the <picture> element.



来源:https://stackoverflow.com/questions/41594359/why-is-srcset-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!