HTML5 srcset:1x 是强制性的吗?
HTML5 srcset: is 1x mandatory?
当使用带有 <img>
且没有断点(即没有 sizes
属性)的响应式图像集时,您通常会提供同一图像的不同分辨率的多个版本,然后在 srcset
使用像素密度语法的属性,例如1x
、2x
、3x
然而,通常图像的 1x
版本与 src
属性中已经定义的图像相同,因此有点多余。因此我想知道 - 在 srcset
参数中定义 <img>
的 1x
版本真的 necessary/mandatory?
仅使用时
<img src="http://placehold.it/350x150" srcset="http://placehold.it/700x300 2x">
而不是
<img src="http://placehold.it/350x150" srcset="http://placehold.it/350x150 1x, http://placehold.it/700x300 2x">
那么至少 FireFox 会正确显示 350x150
图像,一旦缩放 level/dppx 为 > 1
它将使用 700x300
图像。
在 srcset
中省略 1x 定义会节省几个字节,尤其是在具有大型缩略图库的页面上。
If child has a src
attribute whose value is not the empty string and source set does not contain an image source with a density descriptor value of 1, and no image source with a width descriptor, append child's src
attribute value to source set.
这意味着如果 1x
源与 src
属性相同,则可以省略它,但如果使用宽度描述符则不能这样做。
当使用带有 <img>
且没有断点(即没有 sizes
属性)的响应式图像集时,您通常会提供同一图像的不同分辨率的多个版本,然后在 srcset
使用像素密度语法的属性,例如1x
、2x
、3x
然而,通常图像的 1x
版本与 src
属性中已经定义的图像相同,因此有点多余。因此我想知道 - 在 srcset
参数中定义 <img>
的 1x
版本真的 necessary/mandatory?
仅使用时
<img src="http://placehold.it/350x150" srcset="http://placehold.it/700x300 2x">
而不是
<img src="http://placehold.it/350x150" srcset="http://placehold.it/350x150 1x, http://placehold.it/700x300 2x">
那么至少 FireFox 会正确显示 350x150
图像,一旦缩放 level/dppx 为 > 1
它将使用 700x300
图像。
在 srcset
中省略 1x 定义会节省几个字节,尤其是在具有大型缩略图库的页面上。
If child has a
src
attribute whose value is not the empty string and source set does not contain an image source with a density descriptor value of 1, and no image source with a width descriptor, append child'ssrc
attribute value to source set.
这意味着如果 1x
源与 src
属性相同,则可以省略它,但如果使用宽度描述符则不能这样做。