如何使用css指定图像尺寸?

时间:2015-07-13 03:25:06

标签: css

我在gtmetrix上有93%的pagespeed和88%的yslow,但在“指定图像尺寸”上有70%的结果。我该怎么办?

The following image(s) are missing width and/or height attributes.

http://www.cochlea.co.il/wp-content/uploads/2015/06/ab_trans.png (Dimensions: 25 x 25)
http://www.cochlea.co.il/wp-content/uploads/2015/06/cochlear_trans.png (Dimensions: 25 x 25)
http://www.cochlea.co.il/wp-content/uploads/2015/06/medel_trans.png (Dimensions: 25 x 25)
http://www.cochlea.co.il/wp-content/uploads/2015/07/cochleagold.png (Dimensions: 316 x 158)
http://www.cochlea.co.il/wp-content/uploads/2015/07/gmaps-25.png (Dimensions: 25 x 25)
http://www.cochlea.co.il/wp-content/uploads/2015/07/ta.png (Dimensions: 35 x 35)

<img src="/wp-content/uploads/2015/06/ab_trans.png" alt="AB">

1 个答案:

答案 0 :(得分:2)

在HTML中,请务必指定图片的尺寸。

正确:

<img src="http://www.cochlea.co.il/wp-content/uploads/2015/06/ab_trans.png" width="25" height="25" />

不正确(严格来说严格不正确,但效率肯定不高 - 这就是pagespeed / yslow抱怨的内容):

<img src="http://www.cochlea.co.il/wp-content/uploads/2015/06/ab_trans.png" />