CSS圖片等比例縮放代碼

來源:互聯網
上載者:User

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.111cn.net/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">

 代碼如下 複製代碼
.thumbimg { max-width: 530px; max-height: 530px; }/* for firefox & ie7 */
* html .thumbimg {width: expression(this.width > 530 && this.width > this.height ? "530px" :auto); height:expression(this.height >530 ? "530px":auto);}/* for ie6 */

//方法二

 代碼如下 複製代碼
img {
width:expression(this.offsetwidth>160 ? 160 : true); /*自行修改圖片寬度*/
height:expression(this.offsetheight>180 ? 180 : true); /*自行修改圖片高度*/
}

//方法三

 代碼如下 複製代碼

div {
display: table - cell;
/*把塊元素設定為表格元素*/
vertical - align: middle;
/*設定水平置中*/
text - align: center;
/* 針對ie的hack*/
* display: block; * font - size: 180px;
/*把字型大小設定為層的高度*/
* font - family: arial;
/*防止非utf-8引起的hack失效問題*/
width: 160px;
/*自行修改層寬度*/
height: 180px;
/*自行修改層高度*/
border: #ccc 1px solid;
/*顯示層邊框*/
}div img {
vertical - align: middle;
/*設定圖片垂直置中*/
width: expression(this.width > 160 ? 160 : true);
/*自行修改圖片寬度*/
height: expression(this.height > 180 ? 180 : true);
/*自行修改圖片高度*/
}

//方法四

 代碼如下 複製代碼
#thumbimaged img
{
max-width: 120px;
max-height: 140px;
}
/* for firefox & ie7 */
#thumbimaged img
{
/* for ie6 */
width: expression(this.width > 120 && this.width > this.height ?"140px" :auto);
height: expression(this.height > 120 ? "140px" :auto);
}

方法五

 代碼如下 複製代碼
width:expression(this.width > 100 && this.width > this.height ? 100 : true); height: expression(this.height > 100 ? 100 : true);

</style>
</head>

<body>
</body>
</html>

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.