gpt4 book ai didi

html - img 元素上的 HTML 宽度/高度属性和 CSS 宽度/高度属性有什么区别?

转载 作者:技术小花猫 更新时间:2023-10-29 11:50:55 29 4
gpt4 key购买 nike

HTML <img>元素可以有 width/height 属性,也可以有 CSS width/height 属性:

<img src="xxx.img" width="16" height="16"
style="width: 16px; height: 16px"></img>

HTML 属性和 CSS 属性有什么区别,它们应该具有相同的效果吗?

最佳答案

有关该主题的热议可以在这里找到:Width attribute for image tag versus CSS

总结一下:

The gain from declaring a width value and an height value (which may not be the original physical dimensions of the image) or from css declarations (like width: [valueX]; height: [valueY];) is that it helps speed up the rendering of the page. The browser knows how much space to allocate a particular area of the page: it will even draw image placeholders on a first draw, a first parsing+rendering of the page. When one does not define any width and height, then the browser has to download the image and then figure out its dimensions, space to allocate and then redraw the page.

这似乎是我认为最有益的效果。

关于html - img 元素上的 HTML 宽度/高度属性和 CSS 宽度/高度属性有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3562296/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com