Bootstrap 4行填充剩余高度

Ego*_*gor 15 html css grid row bootstrap-4

我正在努力使一排伸展以填补剩余的可用高度.我尝试添加h-100到行类,但这会在屏幕底部产生一个空白区域.必须有办法做到这一点,但我完全难过..这是我的代码:

<div class="container-fluid h-100">
  <div class="row justify-content-center h-100">
    <div class="col-4 bg-red">
      <div class="h-100">
        <div class="row justify-content-center bg-purple">
          <div class="text-white">
            <div style="height:200px">ROW 1</div>
          </div>
        </div>
        <div class="row justify-content-center bg-blue">
          <div class="text-white">ROW 2</div>
        </div>
      </div>
    </div>
    <div class="col-8 bg-gray"></div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

codepen:https://codepen.io/ee92/pen/zjpjXW/ edit = 1100

在此输入图像描述

我想让蓝色行(ROW 2)填满所有红色空间.有什么建议?

谢谢

Zim*_*Zim 26

使用Bootstrap 4.1flex-grow-1类......

https://codepen.io/anon/pen/RyQvmW?editors=1100

html,body{height:100%;}

.bg-purple {
  background: rgb(48,0,50);
}
.bg-gray {
  background: rgb(74,74,74);
}
.bg-blue {
  background: rgb(50,101,196);
}
.bg-red {
  background: rgb(196,50,53);
}
Run Code Online (Sandbox Code Playgroud)

相关:Bootstrap 4:如何使行拉伸剩余高度?


小智 7

这是一个解决方案。包装器div必须有 h-100,div适应高度的必须有 flex-grow-1 和 overflow-auto。这样,div当其内容小于可用空间时,它将增长以填充空间,并在其内容高于可用空间时显示滚动条。

演示 jsfiddle

<div class="h-100 d-flex flex-column bg-yellow px-2">
<div class="flex-column justify-content-center bg-purple px-2">        
    <div class="text-white p-0" style="height:50px">HEADER</div>
</div>

<div class="flex-column justify-content-center bg-red text-white px-2 flex-grow-1 overflow-auto">

        <div>Item1</div>
        <div>Item2</div>
        INNER text 1<br>
        INNER text 2<br>

</div>

<div class="flex-column justify-content-center bg-darkblue px-2">
    <div class="text-white p-0" style="height:50px">FOOTER</div>
</div>                
Run Code Online (Sandbox Code Playgroud)