简体   繁体   中英

How can I set the dimensions in an image CDN using CSS?

CSS

img {
 width: 300px;
 height: 300px;
 }

HTML

<img src="http://images.xxxxxxx.co.uk/content/icon.png" alt="xxxxxxxxx" />

I get the same error in page speed

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

http://images.xxxxxxxxxx.co.uk/content/icon.png (Dimensions: 67 x 75)

there is a solution using .htaccess or jQuery ?

What's wrong with adding them to the image tag:

<img src="http://images.xxxxxxx.co.uk/content/icon.png" width="67px" height="75px" alt="xxxxxxxxx" />

You can't do what you want with JQuery because Search engines / PageSpeed won't render javascript and in turn it won't do anything for crawlers.

This is the same for CSS, the crawler (which is the purpose of the optimisation through PageSpeed) won't run through the CSS so if it's for SEO, CSS won't do either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM