![](/img/trans.png)
[英]How to fit a image into a div without cutting or disturbing its aspect ratio?
[英]how to fit image without stretching and maintain aspect ratio in div tag in html
我的图片尺寸为640 * 820。我想将此图片适合尺寸为310 * 520的屏幕。 在执行此操作时,请保持宽高比(无拉伸)。
<div class="abc" style="
background: url("images/phone.png");
position: absolute;
max-width: 100%;
width: auto;
margin-left:10px;
background-size: contain;
top: 50px;">
您可以只声明图像的宽度并自动设置高度
.div img {
width: 310px;
height: auto;
}
<div class="div">
<img src="#" title="#">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.