html - 如何使图像适合父母的范围?
问题描述
我在将图像放入 zoomContainer 时遇到问题。尽管父级是 66vh,但 img 标签(用 % 代替 vh)不适合 div,而是从顶部和底部溢出。
我希望我的 100% 宽度的 img 适合父级。它似乎更喜欢页面的大小。使用父级而不是页面进行缩放。
.zoomContainer {
height: 66vh;
width: 90vw;
background: white;
margin: auto;
border-radius: 2px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
text-align: center;
position: relative;
}
#b1,
#b2,
#b3,
#b4,
#b5,
#b6,
#b7,
#b8,
#b9,
#b10,
#b11,
#b12,
#b13,
#b14,
#b15,
#b16,
#b17,
#b18 {
padding-left: 1vh;
padding-right: 1vh;
text-align: center;
justify-content: center;
align-items: center;
position: relative;
}
#b10 #logoField10 {
position: relative;
border-radius: 50%;
width: 33.369vh;
transform: rotate(0deg);
border: 2px solid red;
display: block;
}
<div class="zoomContainer zoomTarget selectedZoomTarget zoomNotClickable" style="transform-origin: 864px 309.203px; transform: translate(0px, 0px) rotate(0rad) skewX(0rad) scale(1, 1);">
<div id="b10" class="alive zoomTarget">
<img id="logoField10" data-targetsize="0.6" data-closeclick="true" data-duration="801" src="https://www.thespruce.com/thmb/xqYicKgLaKBjNsBoZibddoEs2U8=/2050x0/filters:no_upscale():max_bytes(150000):strip_icc():format(webp)/109235035-56a8856a3df78cf7729e87a6.jpg"
alt="" srcset="" style="width: 100%" ;>
<p class="BxText">5,623,058<br> Unique Ppl</p>
</div>
</div>
解决方案
Perhaps try align-items: stretch
on the container div
. Either that you can position the child #b10 div absolutely, which makes it position itself relative to the parent and by default stays within the parent, unless you tell it not to, with top, bottom, left, right values.
推荐阅读
- python - Pygame高分不会排序
- python - 尝试使用 scipy 拟合 Pearson3 概率分布
- amazon - 亚马逊支付错误client_Id未定义
- python - python 3中的全局变量声明
- mvc.jquery.datatables - 使用服务器端分页处理在 jquery.datatables 中不显示记录
- python - 如何在 Python 的循环中将加载的表分配给不同的变量?
- outlook - 存储按钮无法从文件安装
- javascript - 在 Chrome 扩展中访问 DOM
- tfsbuild - 有什么方法可以杀死(停止)从代码构建的 TFS 2017 团队?
- javascript - Javascript - 延迟承诺解决