【发布时间】:2023-03-27 14:20:01
【问题描述】:
我有一个使用 bootstrap 4 的 Angular 应用程序。我有一个固定在顶部的导航栏,我想添加填充浏览器剩余空间的内容。除了顶部的导航栏,我还有另一个 div,它本身包含页眉和页脚内容。在页眉和页脚之间,我有一个主要内容部分,我希望该部分(在下面的示例中为#two)填充所有空白空间。
我认为我可以使用 css flexbox 来完成此任务,但是当我进入 bootstrap 世界时,我的简单非引导 flexbox 示例似乎什么也没做。我正在使用these docs 试图解决这个问题。
我认为使用align-self-stretch 应该有助于实现这个目标,但看起来包含元素的大小可能刚好足以容纳我的#outer 内容,所以没有弹性框扩展要做。我天真地尝试将 height:100% 样式添加到包含的 div 中,只是为了尝试进行一些拉伸,但这似乎没有帮助。
我根据@ZimSystem 的回复创建了这个plunker example。他的 codeply 示例似乎完全按照我的意愿工作,但是当我尝试将更改拼凑到我的简单角度代码中时,flex 拉伸没有发生。我不确定我在做什么来破坏它。
这是我目前正在查看的整个角度分量:
<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 充当内容区域的顶部和底部的内容页眉和页脚?
【问题讨论】:
-
当使用百分比表示高度时,确保所有的上升点也有一个高度,即
html, body { height: 100%; }...另一种选择我们使用视口单位,height: 100vh在应用程序容器上
标签: css twitter-bootstrap angular flexbox bootstrap-4