Cómo cambiar el tamaño de las imágenes automáticamente usando estilos JS o CSS
Las versiones js y css que ajustan automáticamente el tamaño de la imagen proporcionalmente son las siguientes:
var?proMaxHeight=?150;
var?proMaxWidth=?110;
función?proDownImage(ImgD){ var?image=new?Image() ; imagen.src= ImgD.src; if(image.width>0?&&?image.height>0){ var?rate?=?(proMaxWidth/image.width?
if(rate?<=?1) { ImgD.width?=?image.width*rate; ImgD.height?=?image.height*rate; ; p>
}
else?{ ImgD.width?=?image.width; ImgD.height?height?=?image.height; } p>
El código CSS puro puede evitar que la imagen explote en la página y la imagen se escalará automáticamente:
.content-width?{MARGIN:?auto;WIDTH:?600px;}
.content-width?img{MAX-WIDTH:?100%!importante; ALTURA:?auto! img{MAX-WIDTH:?100%!important;HEIGHT:?auto! importante;ancho:expresión( this.width?>?600"600px"? :?this.width)!important;}