html - Flexbox,限制可用空间内的图像高度/宽度
问题描述
我有一个固定大小的包装器,包括:
- 大小与内部内容相符的标题
- 固定大小的页脚
- 应该使用包装器剩余空间的内容容器
图像出现问题。我希望图像调整大小以适应内容容器的高度和宽度。现在图像在高度上溢出了包装。
这是代码。宽图像表现正确,调整大小以适应,但长长颈鹿不是。在下面的小提琴溢出设置为滚动到调试。最终目标是没有溢出。 https://jsfiddle.net/sghp68r0/
一个不太灵活的解决方案就是给 imageFit 类一个高度,比如
img {
max-width: 100%;
max-height: 100%;
}
.imageFit {
object-fit: contain;
height: 150px;
}
但这我宁愿避免对高度进行硬编码。
解决方案
如果我是对的,你想要这个。请务必让我知道。
拖动小提琴中的高度,您会看到图像正在调整高度。
这是我的小提琴链接:-
https://jsfiddle.net/exa3y7w9/
<div class="wrapper">
<div class="header">
Sized to content <br />
Sized to content <br />
</div>
<div class="content">
<div class="imageWrapper">
<img src="https://cdn.pixabay.com/photo/2017/10/10/22/24/wide-format-2839089_960_720.jpg">
</div>
<div> 2 images and some text that fills remaining space </div>
<div class="imageWrapper">
<img src="http://clipart-library.com/data_images/258951.jpg">
</div>
</div>
<div class="footer">
There is some text in fixed size container
</div>
</div>
推荐阅读
- javascript - 通过单击带有 js 的按钮添加 div 不能与 PHP 一起使用
- mysql - 如何为音乐曲目列表构建 MySQL 数据库?
- python - 查找多个 artibutes Selenium Python
- ruby-on-rails - 如何使用 React 的回形针向 Rails API 发出带有图像的 API 发布请求
- c# - 将相关数据转换为列表
- git - 如何通过编程在bitbucket/GitHub中提交和推送代码
- python - 管理 dask localcluster 上的 worker 内存
- android - 编译渲染脚本错误“llvm-rs-cc 以非零退出值 127 完成”
- gooddata - GoodData UI 中关于 AttributeFilter 的问题
- java - Android Studio - Java - MediaPlayer 音效有时不起作用