利用CSS按比例缩小图片

系统 1503 0
<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事件。例如:
引用内容
<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>


这固然能解决问题,但是对以后页面的升级会带来麻烦——随着浏览器对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);
}


至于图片是如何保持其高宽比例的,这张图片可以解释:
< 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 >

利用CSS按比例缩小图片


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论