我有一个使用Bootstrap4的棱角应用程序,我有一个粘在顶部的导航栏,我想添加填充浏览器剩余空间的内容.除了顶部的导航栏之外,我还有另一个div,它本身包含页眉和页脚内容.在页眉和页脚之间,我有一个主要内容部分,我希望该部分(下面示例中的#two)填充所有空白.

我以为我可以使用css flexbox来实现这一点,但当我进入bootstrap世界时,我简单的非 bootstrap flexbox示例似乎什么都做不了.我用了these docs来解决这个问题.

我认为使用align-self-stretch应该有助于实现这一目标,但看起来包含元素的大小可能刚好足以容纳我的#outer内容,所以没有flexbox扩展要做.我天真地try 在包含的div中添加height:100%种样式,只是为了进行一些拉伸,但这似乎没有帮助.

我根据@ZimSystem的响应创建了这个plunker example.他的代码编写示例似乎完全按照我的期望工作,但是当我试图将这些更改分段到我的简单Angular 代码中时,伸缩并没有发生.我不确定我该怎么做才能在转换过程中打破它.

enter image description here

这是我现在看到的整个Angular 分量:

<div id="outer" class="d-flex flex-column flex-grow">
    <div id="one" class="">
        header content <br>
        another line <br>
        And another
    </div>
    <div id="two" class="bg-info h-100 flex-grow">
        main content that I want to expand to cover remaining available height
    </div>
    <div id="three" class="">
        footer content
    </div>
</div>

下面是显示导航栏和注入点的应用程序容器:

<div class="d-flex flex-column h-100">
    <nav class="navbar navbar-toggleable-md sticky-top bg-faded">
        <a class="navbar-brand" href="#">
            <h1 class="navbar-brand mb-0">My App</h1>
        </a>
        <ul class="navbar-nav"> 
            <li class="nav-item"><a class="nav-link" routerLink="/flex">My flex view</a></li>
        </ul>
    </nav>
    <router-outlet></router-outlet>
</div>  

如何让我的#two div扩展以填充空间,同时将#one#three div作为内容页眉和页脚锚定在内容区域的顶部和底部?

推荐答案

Update Bootstrap 4.1.0

Bootstrap 4.1.0中包含flex-grow-1flex-fill

Update Bootstrap 4.0.0

添加一个flex-grow类,如下所示:

.flex-grow {
    flex: 1 0 auto;
}

然后,utility classes可以用于布局的其余部分:

 <div class="d-flex flex-column h-100">
    <nav class="navbar navbar-toggleable-md sticky-top bg-faded">
        <a class="navbar-brand" href="#">
            <h1 class="navbar-brand mb-0">My App</h1>
        </a>
        <ul class="navbar-nav">
            <li class="nav-item"><a class="nav-link">Item 1</a></li>
        </ul>
    </nav>
    <div id="outer" class="d-flex flex-column flex-grow">
        <div id="one" class="">
            header content
            <br> another line
            <br> And another
        </div>
        <div id="two" class="bg-info h-100 flex-grow">
            main content that I want to expand to cover remaining available height
        </div>
        <div id="three" class="">
            footer content 40px height
        </div>
    </div>
</div>

https://www.codeply.com/go/3ZDkRAghGU

下面是on Bootstrap 4.3.1的另一个例子,它有一个导航栏、侧栏和带有滚动内容区域的页脚:

Angular相关问答推荐

如何在每次Angular 编译之前执行脚本(esbuild)

Angular 17@在大小写时切换多个值

Sass-Loader中出现分号错误:ANGLE应用程序的缩进语法中不允许使用分号

确保我的角库S服务构建提供独立的友好提供功能

Angular 17:延迟加载带参数的独立组件?

SignalR:协商有效,但消息未发送(.NET/Angular)

Angular 15 在 URL 中使用@进行路由

我应该在 Jasmine 3 中使用什么来代替 fit 和 fdescribe?

可从 Angular2 中的

如何在 Angular4 中访问组件的 nativeElement?

如何在 Angular 4 中使用 Material Design 图标?

Angular 4.3拦截器不起作用

Angular 2:无法绑定到 x,因为它不是已知的本机属性

Angular 5 手动导入语言环境

*ngIf 带有多个异步管道变量

NG2-Charts 无法绑定到 datasets,因为它不是 canvas的已知属性

在 Angular 组件模板中添加脚本标签

提交后在Angular 2中重置表单

Angular 2 输出到router-outlet

如何使用 @ngrx/store 获取 State 对象的当前值?