html - Setting height of img tag equal to its width -


well googled lot didn't find useful.is there way achieve ?

<img src="1.jpg"height="" width="100%"> 

use offsetwidth:

var img = document.getelementsbytagname("img")[0];  img.style.height = img.offsetwidth + "px"; 

and have use javascript.

working demo


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -