【发布时间】:2019-12-25 17:43:48
【问题描述】:
我正在尝试根据设备宽度提供响应式/自适应图像。
原图:
<img src="https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png"/>
使用 Srcset:
<img
src="https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png"
srcset="
https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png?w=400 400w,
https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png?w=800 800w,
https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png?w=1400 1400w,
https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png?w=2000 2000w,
https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png?w=3800 3800w
"
/>
我面临两个问题:
1) 即使在较小的设备(如 iPhone 6s)上,也会加载宽度为 2000px 的图像(它应该加载 800px 的图像)。
2) 我将两个图像(有和没有 srcset)放在一起。他们都加载了相同尺寸的图像。但是,与其他相比,带有 srcset 的那个显得很小。由于在 html/css 中没有指定宽度,它应该以实际图像的宽度呈现,对吧?这是小提琴:https://jsfiddle.net/hfcbatdn/
【问题讨论】:
标签: html css image responsive-images srcset