过去总是将尺寸放入 HTML 代码的原因是由于加载时间——在 14.4K 调制解调器上,即使是相对较小的图像文件也会在主 HTML 文档加载后显着加载。
这些天来,这已经不是什么大问题了。如果这是一个问题,值得注意的是 CSS 文件将在主 HTML 文档之后加载,因此如果您只在那里指定尺寸,您可能会遇到同样的问题,但 CSS 文件通常很小,所以效果应该是最小化。
另一点是老式的 HTML 设计非常注重布局,而图像大小通常是其中的关键部分——如果图像大小错误,整个页面的布局通常会完全错误。
Modern page design approaches things very differently, putting minimal of any layout information into the HTML, and abstracting it all to the stylesheet. Therefore on a typical modern site, until the stylesheets have loaded, the site will just be a series of blocks, and be completely lacking in design. In fact, often the graphics themselves - not just their dimensions - are defined in the stylesheet.
So the answer is that to follow modern page design methods, you should put it in the stylesheet.
Obviously it's critical for most sites these days that the stylesheets load quickly, but it isn't just the size of the graphics that it'll affect.