<span id="voxxx"><output id="voxxx"><nav id="voxxx"></nav></output></span>
<dd id="voxxx"></dd>
<span id="voxxx"><video id="voxxx"><b id="voxxx"></b></video></span>

<span id="voxxx"><sup id="voxxx"></sup></span>
<ruby id="voxxx"></ruby>

<dd id="voxxx"><output id="voxxx"></output></dd>
  • <optgroup id="voxxx"><em id="voxxx"><pre id="voxxx"></pre></em></optgroup>

    0712-2888027 189-8648-0214
    微信公眾號

    孝感風信網絡科技有限公司微信公眾號

    當前位置:主頁 > 技術支持 > HTML5/CSS3 > css控制圖片按等比例縮放實例兼容IE6/IE7/火狐/谷歌

    css控制圖片按等比例縮放實例兼容IE6/IE7/火狐/谷歌

    時間:2023-06-09來源:風信官網 點擊: 1291次
    昨天自己的一個網站需要實現圖片等比例縮放,但又不能使用js只能用css控制div中的img為指定大小,下面我找到一段代碼分離給大家。  

    復制代碼
    代碼如下:

    <style type="text/css">
    .thumbImage img{
    MAX-WIDTH: 100%!important;HEIGHT: auto!important;width:expression(this.width > 600 ? "600px" : this.width)!important;
    }
    .thumbImage {MARGIN: auto;WIDTH: 600px;}
    *html.thumbImage img{
    width:expression(this.width>600&&this.width>this.height?450:auto);
    height:expresion(this.height>450?450:auto);
    }
    </style>

    html代碼代碼如下

    復制代碼
    代碼如下:

    <body>
    <DIV class="thumbImage" ><img src="2007910112041114.jpg" border="0"></DIV>
    </body>

    這樣只要在 class中thumbImage圖片都會等比例縮放哦,小了就原始顯示大的就等比例縮小。

    按比例縮小或者放大到某個尺寸,對于標準瀏覽器(如Firefox),或者最新都IE7,ie8瀏覽器,
    直接使用max-width,max-height;或者min-width,min-height的CSS屬性即可。如:
     

    復制代碼
    代碼如下:

    img{max-width:100px;max-height:100px;}
    img{min-width:100px;min-height:100px;}

    對于IE6及其以下版本的瀏覽器,則可以利用其支持的expression屬性,在css code中嵌入javascript code來實現圖片的縮放,如下:

    復制代碼
    代碼如下:

    .thumbImage {max-width: 100px;max-height: 100px;} /* for Firefox & IE7 */
    * html .thumbImage { /* for IE6 */
    width: expression(this.width > 100 && this.width > this.height ? 100 : auto);
    height: expression(this.height > 100 ? 100 : auto);
    }

    首頁產品展示的圖片都變形了,客戶要求圖片等比例大小,和產品展示的效果一樣:

    找到的相關知識:

    css控制圖片的等比縮放
    css樣式代碼
     

    復制代碼
    代碼如下:

    <style type="text/css">
    img {max-width:500px; max-height:500px; scale:expression((this.offsetWidth > this.offsetHeight)?(this.style.width = this.offsetWidth >= 500 ? "500px" : "auto"):(this.style.height = this.offsetHeight >= 500 ? "500px" : "auto")); display:inline !important;}
    </style>

    示例中是默認網頁所有的img的標簽中的圖片都會縮放,如果想讓特定的圖片縮放只要修改下前面的css名字,然后在網頁中調用就可以了

    隨便看看頁面圖片強制等比縮放,發有修改前后對照圖

    不是專業人員,沒有利用較高難度寫JS或者css,只是為了網站美觀,把網站版面美化的一些經驗分享一下??!

    為使大家一目了然,發有對照圖,可以發現簡單的改動確實能夠美化頁面!

    隨便看看頁面的圖片不會等比縮放,而是直接壓縮成100*100px,為此,簡單改css進行圖片強制等比縮放

    實例看看就明白了!

    原版HOME隨便看看圖片效果:

     

     修改后圖片效果:

     

    修改位置:network.css

    修改內容:
     

    復制代碼
    代碼如下:

    #spics .spic_img img { width: 100px; height: 100px; }

    直接替換為:

    復制代碼
    代碼如下:

    #spics .spic_img img { max-width: 100px; max-height: 100px; zoom: expression( function(elm) { if (elm.width > 100 || elm.height > 100 ){ if (elm.width>elm.height) { elm.width=100; } else{ elm.height=100; } } elm.style.zoom = '1'; }(this) ); }

    純CSS實現圖片等比縮放兼容IE6/IE7/火狐/谷歌
    代碼如下:

    復制代碼
    代碼如下:

    <!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實現圖片等比縮放兼容IE6/IE7/火狐/谷歌_懶人建站</title>
    <style type="text/css">
    .suofang {MARGIN: auto;WIDTH: 800px;}
    .suofang img{MAX-WIDTH: 100%!important;HEIGHT: auto!important;width:expression(this.width > 800 ? "800px" : this.width)!important;}
    </style>
    </head>
    <body>
    <div class="suofang">
    <img src="http://www.51xuediannao.com/uploads/jiqiao/csssuofang/blogbus.png"/>
    </div>
    </body>
    </html>
    欄目列表
    推薦內容
    熱點內容
    展開
    亚洲国产精品无码久久电影
    <span id="voxxx"><output id="voxxx"><nav id="voxxx"></nav></output></span>
    <dd id="voxxx"></dd>
    <span id="voxxx"><video id="voxxx"><b id="voxxx"></b></video></span>

    <span id="voxxx"><sup id="voxxx"></sup></span>
    <ruby id="voxxx"></ruby>

    <dd id="voxxx"><output id="voxxx"></output></dd>
  • <optgroup id="voxxx"><em id="voxxx"><pre id="voxxx"></pre></em></optgroup>