繁体   English   中英

如何在不拉伸的情况下适合图像并在html的div标签中保持纵横比

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM