Bootstrap 4 Holy Grail Layout

前提是你 提交于 2019-11-30 07:35:27

Make sure the center column is flex-column, and then use flex-grow:1 for the main content. In this example, I only have the sidebars fixed width on larger screens, but you may decide to change this.

http://www.codeply.com/go/licdodtBCO

<div class="container-fluid h-100">
    <div class="row h-100">
        <!-- left sidebar -->
        <div class="col-md-2 fixed">

        </div>
        <!-- center content -->
        <div class="col fluid d-flex flex-column">
            <nav id="topNav" class="navbar"> 
            </nav>

            <!-- main content -->
            <div class="row flex-grow">

            </div>

            <footer class="navbar navbar-toggleable-xl navbar-faded navbar-light">
            </footer>

        </div>
        <!-- right sidebar -->
        <div class="col-md-2 fixed">

        </div>
    </div>
</div>

CSS

html {
    height: 100%;
}

body {
    min-height: 100vh;
}

/* fixed and fluid only on sm and up */
@media (min-width: 576px) {
    .fixed {
        flex: 0 0 200px;
        min-height: 100vh;
    }
    .col .fluid {
       min-height: 100vh;
    }
}

.flex-grow {
   flex:1;
}

Bootstrap 4 Holy Grail Demo

Bootstrap 4 Fixed-Fluid-Fixed

Note: It's important to note that in the classic "holy grail" layout, the term "fixed" refers to width, and not position as in position:fixed. However, with a few tweaks it's possible to get both fixed width and position. For example, here's an alternate "holy grail" layout with left side bar fixed width and position: https://www.codeply.com/go/s90QZLC0WT

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!