[英]picture element, responsive images, webp images and safari fallback not working
I would like to use webp images, of course safari doesn't support them so I also added the jpg's as fallbacks for different resolutions.我想使用 webp 图像,当然 safari 不支持它们,所以我还添加了 jpg 作为不同分辨率的后备。
In chrome everything works fine, in safari it only works if I remove the webp versions from the image tag.在 chrome 中一切正常,在 safari 中只有当我从图像标签中删除 webp 版本时才有效。
But I don't want to abandon webp images just because of safari...但我不想仅仅因为 safari 就放弃 webp 图像......
My html code is below.我的 html 代码如下。
<picture>
<source type="image/webp" media="(max-width: 1200px)" srcset="/public/images/picture0-m.webp">
<source type="image/webp" media="(min-width: 1201px)" srcset="/public/images/picture0.webp">
<source type="image/jpeg" media="(max-width: 1200px)" srcset="/public/images/picture0-m.jpg">
<source type="image/jpeg" media="(min-width: 1201px)" srcset="/public/images/picture0.jpg">
<img src="/public/images/picture0-m.jpg"type="image/jpeg">
</picture>
Recovering an old question - but it was one of the first links that I found when I had the same issue.恢复一个旧问题 - 但它是我遇到相同问题时发现的第一个链接。
I resolved this by adding a srcset
to the <img>
tag:我通过向
<img>
标签添加一个srcset
来解决这个问题:
<picture>
<source sizes="(min-width: 1200px) 864px, (min-width: 992px) 708px, (min-width: 768px) 540px, calc(100% - 4rem)" srcset="img.webp 345w, img2.webp 650w, img3.webp 1024w" type="image/webp">
<source sizes="(min-width: 1200px) 864px, (min-width: 992px) 708px, (min-width: 768px) 540px, calc(100% - 4rem)" srcset="img.jpg 345w, img2.jpg 650w, img3.jpg 1024w" type="image/jpg">
<img src="img.jpg" srcset="img.jpg 345w, img2.jpg 650w, img3.jpg 1024w" alt="Whale">
</picture>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.