是否有一种方法来调整(缩小)图像按比例使用CSS?

我用的是JavaScript的方式,只是想看看CSS是否可行。


当前回答

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

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

其他回答

Image_tag ("/icons/icon.gif",高:'32',宽:'32') 我需要设置高度:'50px',宽度:'50px'到图像标签,这段代码从第一次尝试开始工作注意,我尝试了上面所有的代码,但运气不好,所以这段代码可以工作,下面是我的_nav.html.erb的代码: < % = image_tag (" # {current_user。图像}",高度:'50px',宽度:'50px') %>

使用这种简单的缩放技术

img {
    max-width: 100%;
    height: auto;
}
@media {
  img { 
    width: auto; /* for ie 8 */
  }
}

试试这个:

div.container {
    max-width: 200px;//real picture size
    max-height: 100px;
}

/* resize images */
div.container img {
    width: 100%;
    height: auto;
}

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

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

我们可以在浏览器中使用CSS调整图像大小,使用媒体查询和响应式设计原则。

    @media screen and (orientation: portrait) {
img.ri {
    max-width: 80%;
  }
}

@media屏幕和(方向:横向){ img。Ri {max-height: 80%;} }