如果我们使用的是srcset和sizes属性,那么指定一个src属性作为后盾仍然是有用的。类似地,如果指定了width和height属性,我设想旧的浏览器也会利用它们。但是现代浏览器呢?
例如:
<img
src="foo100x100.jpg"
srcset="foo100x100.jpg 100w, foo500x500.jpg 500w, foo900x900 900w"
sizes="100vw"
width="100"
height="100"
alt="example"
>在本例中,width和height属性对现代浏览器有什么用处吗?
发布于 2016-05-09 21:27:23
根据实验,它的行为就好像您指定了以像素为单位的width和height CSS属性。但是,它可以被您自己的CSS覆盖。
img {
width: 200px;
/* height will be 100px because of the HTML attribute */
}<img
src="http://placehold.it/100x100"
srcset="http://placehold.it/100x100 100w, http://placehold.it/500x500 500w"
sizes="100vw"
alt=""
width="100"
height="100"
>
这有点令人失望,因为我希望现代浏览器在下载图像之前使用width和height HTML属性来确定图像的纵横比,以避免在页面加载时出现以下内容跳转的布局。
https://stackoverflow.com/questions/37125773
复制相似问题