用css來控製圖片大小顯示的實現方法與代碼_經驗交流

來源:互聯網
上載者:User
有時候圖片太大,會破環網頁整齊的布局。這時可以用css來強制按比例壓縮圖片的高度或寬度
css代碼如下:
img,a img{
border:0;
margin:0;
padding:0;
max-width:590px;
width:expression(this.width>590?"590px":this.width);
max-height:590px;
height:expression(this.height>590?"590px":this.height);
}
這樣當圖片的高度或寬度若超過590px,將會按比例壓縮成590px,如果不超過則按原大小顯示。
  • 相關文章

    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.