[英]img srcset and sizes not working as I would expect
我目前正在尝试在我的网站上制作更好的响应式图像。 经过一番研究,我发现了srcset
和sizes
属性。
我的目标如下:
这就是我想出的。 但它不像我想的那样工作。 始终提供 250x250 的小型广告。
<img src="https://placehold.it/250"
srcset="https://placehold.it/700 700w, https://placehold.it/500 500w, https://placehold.it/350 350w, https://placehold.it/250 250w"
sizes="((max-width: 600px) and (min-width: 300px) and (min-resolution: 2)) 350px, (min-resolution: 2) 250px, ((max-width: 600px) and (min-width: 300px)) 350px, 250px" />
我还有一个问题:
在我的测试中,我发现当调整窗口大小时浏览器不会加载新图像,因此应该提供不同的图像。 有可能这样做吗?
好的。 一些tidious研究后,我发现我不明白sizes
正确-attribute。
以下是我如何实现我想要的:
<img src="https://placehold.it/250"
srcset="https://placehold.it/700 700w, https://placehold.it/500 500w, https://placehold.it/350 350w, https://placehold.it/250 250w"
sizes="(max-width: 600px) calc(100vw - 50px), 250px" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.