auto reduce the image size

1.use the css style
<style type="text/css">
.content-width {MARGIN: auto;WIDTH: 600px;}
.content-width img{MAX-WIDTH: 100%!important;HEIGHT: auto!important;width:expression(this.width > 600 ? "600px" : this.width)!important;}
</style>
</head>
<body>

<div class="content-width">
  <p><img src="/down/js/images/12567247980.jpg"/></p>
  <p><img src="/down/js/images/12567247981.jpg"/></p>
</div>

2. use javascript code
  <script language="JavaScript">
var imgObj;
for( i = 0; i < document.getElementsByTagName("img").length; i++ )
{
 imgObj = document.getElementsByTagName("img")[i];
 if ( imgObj.width > 400) 
 {
  imgObj.width = 400
 }
 if ( imgObj.height > 400 ) 
 {
  imgObj.height = 400
 }
}
</script>

你可能感兴趣的:(JavaScript,java,css)