引导栏全高,如有需要,可使用滚动条

我有以下(一种)代码:

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" style="min-height: 100vh;">
  <div class="row">
    <div class="col-8">
      <div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col">
              header
            </div>
          </div>
          <div class="row">
            <div id="logo-frame" class="col d-flex justify-content-center align-items-center">
              <img src="https://via.placeholder.com/1000x300" class="img-fluid overflow-auto">
            </div>
          </div>
          <div class="row">
            <div class="col">
              footer
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-4">
      <div class="card">
        <div class="card-body">
          side
        </div>
      </div>
    </div>
  </div>
</div>

图像是动态加载的,可以是任何大小和纵横比。 我希望div#logo-frame为:

  • 占用所有可用的垂直空间(容器有min-height: 100vh,但我不确定如何让div用flexbox完全吃掉它),并在需要时用空格填充图像
  • 使图像的内部水平和垂直居中(我认为我被justify-content-center align-items-center覆盖了)
  • 如果高度太大而无法显示图像(例如,使用https://via.placeholder.com/1000x2000),则仅显示图像,而不显示整页(我认为overflow-auto足够,但不显示图像)当然...)

如何使用flexbox轻松实现此行为? 谢谢

更新

以下代码有效。

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper">
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" style="height : 100vh">
  <div class="row h-100">
    <div class="col-8 h-100">
      <div class="card h-100">
        <div class="card-body d-flex flex-column h-100">
          <div class="row">
            <div class="col">
              header
            </div>
          </div>
          <div class="row h-100 overflow-auto">
              <div id="logo-frame" class="col d-flex justify-content-center align-items-center">
                <img src="https://via.placeholder.com/1000x300" class="img-fluid">
            </div>
          </div>
          <div class="row">
            <div class="col">
              footer
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-4">
      <div class="card">
        <div class="card-body">
          side
        </div>
      </div>
    </div>
  </div>
</div>
</div>

有人可以帮我理解吗?

  1. 是否有可能不必级联h-100
  2. 为什么我放min-height:100vh而不是height:100vh却不起作用?
  3. 为什么如果我不将d-flex flex-column放在card-body元素上,它将不起作用
  4. 是否有更好的方法可以完成这项工作?
lk2009xx 回答:引导栏全高,如有需要,可使用滚动条

您是否考虑过结合使用父容器中的“ max-height” css属性和溢出时自动滚动功能?

根据您的请求更新

<!-- Add Slimscroll library -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/jQuery-slimScroll/1.3.8/jquery.slimscroll.js" rel="stylesheet" />

重构标记

<div class="container-fluid" style="min-height: 100vh;">
<div class="row">
    <div class="col-8">
    <div class="card">
        <div class="card-body">
        <div class="row">
            <div class="col">
            header
            </div>
        </div>
        <div class="row">
            <!-- as indicated in style attribute: Add a class w/these attribs/values -->
            <div id="logo-frame" style="max-height: 1000px; overflow: hidden;" class="col d-flex justify-content-center align-items-center">
            <!-- you might need to remove the css selector: overflow-auto from the class attrib (Test it) -->
                <img src="https://via.placeholder.com/1000x1200" class="img-fluid">
            </div>
        </div>
        <div class="row">
            <div class="col">
            footer
            </div>
        </div>
        </div>
    </div>
    </div>
    <div class="col-4">
    <div class="card">
        <div class="card-body">
        side
        </div>
    </div>
    </div>
</div>

在加载时实例化超薄滚动

$(document).ready(function () {
    $('#logo-frame').slimScroll({  
        // According to slimscroll documentation - leave height empty      
        height: '',width: '100%',alwaysVisible: false
    });
})    
本文链接:https://www.f2er.com/3149174.html

大家都在问