Resize image proportionally with CSS?

Is there a way to resize (scale down) images proportionally using ONLY CSS?

I'm doing the JavaScript way, but just trying to see if this is possible with CSS.


要使用CSS按比例调整图像大小:

img.resize {
    width:540px; /* you can use % */
    height: auto;
}

控制大小和保持比例:

#your-img {
    height: auto; 
    width: auto; 
    max-width: 300px; 
    max-height: 300px;
}

If it's a background image, use background-size:contain.

Example css:

#your-div {
  background: url('image.jpg') no-repeat;
  background-size:contain;
}
链接地址: http://www.djcxy.com/p/88854.html

上一篇: 如何动态更改网页的标题?

下一篇: 用CSS按比例调整图像大小?