【发布时间】:2017-06-20 06:35:56
【问题描述】:
我的问题是子图像元素必须适合父 div,但图像的高度和宽度是动态设置的。
.people-image-right-parent { height: 150px; width: 150px;background: #EAEAEA; overflow: auto; }
.people-image-right{ width: 220px;
object-fit: contain;
height: 220px;
background: url(http://ndl.mgccw.com/mu3/000/488/937/sss/68ad9b3f576e42399021560560fb3a16_small.png) -491px -235px;}
<div class="people-image-right-parent">
<img class="people-image-right" />
</div>
图像的高度和宽度是动态的,不是固定的,应该以像素 (px) 为单位。我不希望图像可滚动或隐藏。它必须适合父元素或必须包含在父元素中。
请指导我如何使图像适合其父 div。
提前致谢。
【问题讨论】:
-
people-image-right 在 html 中是 id,但在 css 中你的目标是类
-
@jakob 我修改了我的问题。
-
你设置的图像高度宽度大于 div 标签这就是为什么不正确可见@AkashChavda
-
@Bhargav 是的,你是对的,但这是我的情况,所以子图像元素如何适合父 div 元素。