本文章提供一款css 图片自动缩放代码,本款代码是选固定图片大小,如果当前图片的大小大于固定大小就对图片进行缩放否则就原图片不动。
代码如下
复制代码
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>css 图片自动缩放</title>
<style type="text/css">
.imgsize {
width:expression(this.width>78?"78px":this.width+"px");
height:expression(this.height>78?"78px":this.width+"px");
}
/*
兼容ie ,ff,ie7等浏览器做法
*/
max-width: 250px;
max-height: 186px;
width:expression(this.width > 250 ? 250 : true);
height: expression(this.height > 186 ? 186 : true);
</style>
</head>
<body>
<img src="/upfile/borough/picture/2010/06/26/20100626010000.jpg"class="imgsize"/>
<img src="/upfile/borough/picture/2010/07/19/20100719154725.jpg"class="imgsize"/>
</body>
</html>