我有一个使用引导程序4的角度应用程序。我有一个导航栏粘贴到顶部,我想添加填充浏览器剩余空间的内容。除了顶部的导航栏,我还有另外一个div,它本身包含页眉和页脚内容。在页眉和页脚之间,我有一个主要内容部分,并且我希望该部分(在下面的示例中为#two
)填充所有空白空间。如何使用Bootstrap 4 flexbox填充可用内容?
我认为我可以使用css flexbox来实现这一点,但是当我进入bootstrap世界时,我的简单非bootstrap flexbox示例似乎什么也不做。我正在使用these docs来试图解决这个问题。
我认为使用align-self-stretch
应该有助于实现这一目标,但它看起来像包含的元素可能只是大到足以容纳我的#outer
内容,所以没有flexbox扩展可以完成。我试着天真地试图加入height:100%
样式到包含的div,只是为了试图拉伸,但这似乎没有帮助。
我根据@ ZimSystem的回应创建了这个plunker example。他的代码示例似乎完全按照我想要的方式工作,但是当我试图将更改分解为简单的角码时,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
divs充当内容页眉和页脚锚定到内容区域的顶部和底部?
当使用百分比来表示高度时,确保所有的顶点都有一个高度,例如'html,body {height:100%; }'...另一种选择我们使用视口单元,而应用程序容器上的'height:100vh' – LGSon