html - 使图像仅为父容器高度的 100%
问题描述
我遇到了用户在内容编辑器中缩放图像的问题。
如果他们将大版本的低分辨率图像拖到这个全宽 div 中,它们会水平和垂直拉伸,并且只能看到图像的中间部分并且是颗粒状的。
我试图确保放置在fullContent
div 中的任何图像都是居中的,并且只有该 div 的高度,以便宽度相应地缩放。基本上试图使整个图像居中,但无论大小如何都能完全看到
<style type="text/css">
html,
body {
height: 100vh;
width: 100vw;
overflow: hidden;
}
iframe{
height:100% !important;
width:100% !important;
}
.middle p{
max-height:100%;
margin-bottom:0;
display: flex
}
img {
object-fit: scale-down;
width: 100%;
margin:0 auto;
}
#fullContent{
display:flex;
justify-content:center;
align-items:center;
overflow: hidden;
}
#fullContent img{
object-fit: contain;
}
.fullContent {
max-width: 100%;
max-height: 100%;
height: auto;
width: auto;
}
.fullContent > img{
min-width:100%;
min-height: 100%;
width: auto;
height: auto;
}
.my-container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width:100vw;
}
.my-container .top.row,
.my-container .row.bottom {
flex-shrink: 0;
}
.my-container>.top [class^="col-"],
.my-container>.bottom [class^="col-"] {
background-color: #778899 ;
color: white;
text-align: center;
}
.my-container>.middle {
flex-grow: 1;
padding:30px;
/*background-image: url('images/bg_green.svg');*/
background-size: cover;
}
</style>
<div class="container-fluid my-container d-flex h-100">
<div class="row top">
<div class="col-lg-12">
<div class="row" style="background-color: #778899;">
<h2>top row</h2>
</div>
</div>
</div>
<div class="row middle" id="middle" style="background-image: url();">
<div class="col-lg-12" id="fullColumn">
<div class="fullContent" id="fullContent">
<p><img src="https://via.placeholder.com/1900x2300"/></p>
</div>
</div>
</div>
<!-- End Row Middle -->
<div class="row bottom">
<div class="col-lg-12">
<div class="row" style="background-color: #778899;">
<h2>bottom row</h2>
</div>
</div>
</div>
</div>
解决方案
推荐阅读
- reactjs - 使用 react-dnd 时,如何指定 DragPreviewImage 的 HTML 属性?
- fragment - 带有navhostfragment的BottomNavigationView不显示片段,android?
- r - R中重复的数据框行
- javascript - 在 Next Js 的内部页面的 getStaticProps 函数中找不到文件路径
- python - 如何使用 Python 中的 requests 包通过 API 密钥获取 API 答案
- android - 如何在 Android 上删除弹出窗口“USB OTG”。(小米)
- windows - 没有活动窗口时如何创建上下文相关的热键?
- cmake - 为什么 CMAKE_SIZEOF_VOID_P 在 64 位机器上表示 32 位?
- magento - magento 2.4 结帐时未显示送货地址
- linux - 插入电缆后停止 RTP 多播