【发布时间】:2017-11-20 13:11:37
【问题描述】:
我一直在努力尝试让响应式图像在我正在构建的这个网站上运行,当我认为它进展顺利时,我在 iPad 视网膜屏幕上查看它,它选择了错误的图像。它不仅尺寸错误,而且还显示为横向,而不是纵向。我不知道为什么要这样做,因为我已经为所有不同的屏幕尺寸创建了自定义图像尺寸,并且还创建了用于视网膜屏幕的 XL 版本。
这是带有 srcset 和尺寸的图像的 HTML。
<img class="scene_element scene_element--fadeinup" src="http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-505x757.jpg"
srcset="http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017.jpg 3684w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-768x1151.jpg 768w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-1010x1514.jpg 1010w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-505x757.jpg 505w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-415x622.jpg 415w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-720x1080.jpg 720w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-360x540.jpg 360w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-293x440.jpg 293w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-1110x800.jpg 1110w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-455x306.jpg 455w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-355x238.jpg 355w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-640x600.jpg 640w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-320x300.jpg 320w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-2340x1258.jpg 2340w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-1170x629.jpg 1170w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-940x627.jpg 940w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-555x400.jpg 555w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-1910x1274.jpg 1910w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-955x637.jpg 955w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-1574x1250.jpg 1574w,
http://localhost:8888/wp-content/uploads/2017/11/Westfield-House-049-March-2017-787x625.jpg 787w"
sizes="(-webkit-min-device-pixel-ratio: 1.5) 1010px,
(max-width: 767px) 767px, (min-width: 768px) and (max-width: 991px) 415px,
(min-width: 992px) and (max-width: 1199px) 415px,
(min-width:1200px) 505px, 505px" itemprop="thumbnail" alt="Image description" >
由于视网膜屏幕是双像素,我首先尝试将其添加到针对 iPad 的尺寸,但没有任何反应:
(min-width: 2048px) 1010px
有趣的是,我有一个尺寸为 1010 像素的图像,并指定了当它是使用该图像的两倍像素时的大小。相反,它使用这个尺寸:940x627.jpg
谁能解释一下为什么会这样?
【问题讨论】:
-
这些是很多源集 O.o 你确定你绝对需要每个人吗?通常 3 或 4 个就足够了...
-
嗨,Dingo,是的,你是对的。我在 Wordpress 中创建了许多不同的自定义尺寸,用于整个站点的不同图像,我想要做的是能够在您使用移动设备时更改纵横比。由于 Wordpress 默认只选择具有相同比例的图像,因此我不得不使用 wp_calculate_image_srcset 将其他尺寸添加到 srcset 中。这并不理想,因为它现在将所有图像尺寸添加到所有图像中。我希望有更多的控制权并选择我想在不同图像上加载的图像,但我对此很陌生,我能做的最好的就是让它们全部加载
-
我刚刚在这里问了一个类似的问题:stackoverflow.com/questions/47460761/…
标签: wordpress responsive-design responsive-images srcset