我正在处理图像,我遇到了长宽比的问题.
<img src="big_image.jpg" width="900" height="600" alt="" />
如您所见,已经指定了height
和width
.我为图像添加了CSS规则:
img {
max-width: 500px;
}
但是big_image.jpg
元,我会得到width=500
元和height=600
元.如何设置要调整大小的图像,同时保持它们的纵横比.
我正在处理图像,我遇到了长宽比的问题.
<img src="big_image.jpg" width="900" height="600" alt="" />
如您所见,已经指定了height
和width
.我为图像添加了CSS规则:
img {
max-width: 500px;
}
但是big_image.jpg
元,我会得到width=500
元和height=600
元.如何设置要调整大小的图像,同时保持它们的纵横比.
img {
display: block;
max-width:230px;
max-height:95px;
width: auto;
height: auto;
}
<p>This image is originally 400x400 pixels, but should get resized by the CSS:</p>
<img width="400" height="400" src="http://i.stack.imgur.com/aEEkn.png">
这将使图像缩小,如果它对指定的区域太大(作为缺点,它不会放大图像).