Bootstrap4布局问题-用内容填充浏览器页面高度

时间:2020-03-02 11:27:09

标签: html css bootstrap-4 flexbox

我们应该创建以下布局面板: A complicated layout

#2面板包含更少或更多的行,因此其垂直大小无法静态计算。 #3和#4应该填充浏览器窗口底部的剩余高度。 #3应该可以垂直滚动,因为它可能包含大量的“行”。

如何使用Bootstrap 4预定义CSS样式构建此布局?有可能吗?

这是一种...尝试:

<div class="container-fluid">
    <div class="row">
        <div class="col-4 bg-red vh-100">
            #1 Some content on the left side<br>
            should be full height
        </div>
        <div class="col-8 bg-cyan">
            <h1>#2 Some content L1</h1>
            <h1>Some content L2</h1>
            <h1>Some content L3</h1>
            <h1>Some content L4</h1>
            <div class="container-fluid h-100">
                <div class="row h-100">
                    <div class="col-4 bg-blue overflow-auto">
                        #3 should fill remaining vertical space<br>
                        overflow-Y scroll is needed<br>
                        extra ROW 1<br>
                        extra ROW 2<br>
                        extra ROW 3<br>
                        extra ROW 4<br>
                    </div>
                    <div class="col-8">
                        <div class="bg-green">#4 content</div>
                        <div class="bg-darkgreen">#5 footer line 1 at the bottom of page</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

任何建议都非常欢迎!

1 个答案:

答案 0 :(得分:2)

您可以使用flex-grow和max-height(mh-100)。使滚动div(#3)position-absolute ...

<div class="container-fluid">
    <div class="row min-vh-100 mh-100">
        <div class="col-4 bg-red bg-danger"> #1 Some content on the left side<br> should be full height </div>
        <div class="col-8 bg-info d-flex flex-column mh-100">
            <h1>#2 Some content L1</h1>
            <h1>Some content L2</h1>
            <h1>Some content L3</h1>
            <h1>Some content L4</h1>
            <div class="row flex-grow-1 flex-shrink-1 overflow-hidden">
                <div class="col-4 bg-primary overflow-auto">
                    <div class="position-absolute">
                    #3 should fill remaining vertical space<br> overflow-Y scroll is needed<br>
                    extra ROW 1<br> extra ROW 2<br> extra ROW 3<br> extra ROW 4<br> extra ROW 4<br> extra ROW 4<br>
                     extra ROW 4<br> extra ROW 4<br> extra ROW 4<br> extra ROW 4<br>
                    </div> 
                </div>
                <div class="col-8 d-flex flex-column px-0">
                    <div class="bg-success flex-grow-1">#4 content</div>
                    <div class="bg-dark">#5 footer line 1 at the bottom of page</div>
                </div>
            </div>
        </div>
    </div>
</div>

https://www.codeply.com/p/DUIcgBdd6Y