gpt4 book ai didi

html - 在特定尺寸的 div 中适合不同尺寸的图像

转载 作者:太空宇宙 更新时间:2023-11-03 22:59:24 25 4
gpt4 key购买 nike

我有不同尺寸的图片(1920 x 1080)。

我想将这张图片放入具有样式的 div 中我看到样式指定为的 css 文件

.detail-img{ width:100%; max-height:350px; overflow:hidden; margin-bottom:30px;}
.detail-img img, .detail-img-a img{width:100%;}
.detail-img-a{ width:100%; margin-bottom:15px;}

在html页面中div就像

<div class="detail-img">
<img src="<%= @event.avatar.url %>">
</div>

原图是

enter image description here

但它显示为 enter image description here

有没有办法适合我的 div?

最佳答案

你必须为图片设置最大宽度

  .detail-img img{
max-width: 100%;
}

关于html - 在特定尺寸的 div 中适合不同尺寸的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37051954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com