<script type="text/javascript"><!-- google_ad_client = "pub-7655768891627260"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; //2007-07-16: 酷哥广告渠道 google_ad_channel = "5559849160"; google_ui_features = "rc:0"; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>把一副大图片按比例缩小到某个尺寸,对于现代浏览器,直接使用max-width和max-height两条CSS属性即可。阅读全文...
对于IE6.0及以下版本,以上两条CSS属性均不会被理会。之前处理这种事情,我们往往会借助Javascript,然后为图片加上onload事件。例如:
这固然能解决问题,但是对以后页面的升级会带来麻烦——随着浏览器对CSS支持的完善,我们迟早会把图片上的onload事件统统去除。该是Expression的ShowTime了,既然IE支持通过Expression在CSS中放置一些脚本,而这段脚本又只是提供给IE6.0及以下版本使用,那么把它写到Expression中再合适不过。
最终,把一副大图片按比例缩小到50px*50px以内,可以参照以下这段CSS:
至于图片是如何保持其高宽比例的,这张图片可以解释:
<
scripttype
=
"
text/javascript
"
><!--
google_ad_client
=
"
pub-7655768891627260
"
;
google_ad_width
=
728
;
google_ad_height
=
90
;
google_ad_format
=
"
728x90_as
"
;
google_ad_type
=
"
text_image
"
;
//
2007-07-16:酷哥广告渠道
google_ad_channel
=
"
5559849160
"
;
google_ui_features
=
"
rc:0
"
;
//
-->
</
script
>
<
scripttype
=
"
text/javascript
"
src
=
"
http://pagead2.googlesyndication.com/pagead/show_ads.js
"
>
</
script
>
对于IE6.0及以下版本,以上两条CSS属性均不会被理会。之前处理这种事情,我们往往会借助Javascript,然后为图片加上onload事件。例如:
引用内容
<imgsrc="..."alt="..."onload="resizeImage(this)"/>
<scripttype="text/javascript">
functionresizeImage(obj){
obj.width=obj.width>50&&obj.width>obj.height?50:auto;
obj.height=obj.height>50?50:auto;
}
</script>
<scripttype="text/javascript">
functionresizeImage(obj){
obj.width=obj.width>50&&obj.width>obj.height?50:auto;
obj.height=obj.height>50?50:auto;
}
</script>
这固然能解决问题,但是对以后页面的升级会带来麻烦——随着浏览器对CSS支持的完善,我们迟早会把图片上的onload事件统统去除。该是Expression的ShowTime了,既然IE支持通过Expression在CSS中放置一些脚本,而这段脚本又只是提供给IE6.0及以下版本使用,那么把它写到Expression中再合适不过。
最终,把一副大图片按比例缩小到50px*50px以内,可以参照以下这段CSS:
引用内容
.thumbImage{
max-width:50px;
max-height:50px;
}
*html.thumbImage{
width:expression(this.width>50&&this.width>this.height?50:auto);
height:expresion(this.height>50?50:auto);
}
max-width:50px;
max-height:50px;
}
*html.thumbImage{
width:expression(this.width>50&&this.width>this.height?50:auto);
height:expresion(this.height>50?50:auto);
}
至于图片是如何保持其高宽比例的,这张图片可以解释:
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)
![](http://img.it610.com/image/product/ff68a22582454f78825e64e5346ca758.gif)