【发布时间】:2020-07-11 07:16:54
【问题描述】:
有没有办法在不拉伸的情况下将图像放入固定大小的 div 中?
我的图像不能是横向或纵向的,无法容纳在 250 像素的 div 中,问题是 ut 真的被拉伸了。
实际图片尺寸:
当前结果:
CSS 代码:
.container {
position: relative;
width: 250px;
height: 250px;
margin-bottom: 30px;
}
.container img {
width: 100%;
height: auto;
}
HTML 代码:
<div class="row text-center text-lg-left">
<div th:each="inst, iStat : ${instances}" class="container"
th:if="${inst.fileStatus} eq ${T(br.com.macrosul.stetho.entity.FileStatus).UPLOADED}">
<a href="#" class="d-block mb-4 h-100"> <img class="img"
data-target="#showMedia" data-toggle="modal"
th:data-slide-to="${iStat.index}"
style="width: 100%; height: 100%"
th:src="@{'/instances/' + ${inst.id} + '/thumbnail' + ${folder != null ? '?folder=' + folder.id : ''}}"
alt="">
</a>
</div>
</div>
【问题讨论】:
标签: html css image image-size