简体   繁体   English

如何使中心行填充100%的页面高度?

[英]how can I make a center row fill 100% of the page height with Material?

I'd like to get a title bar and a footer with a content section in the middle (that takes up the rest of the available height) with Angular Material. 我想使用Angular Material获得一个标题栏和一个页脚,其中一个内容部分位于中间(占可用高度的其余部分)。 I've been messing with it for a while now and reading the docs but I feel like I must be missing something with how Material decides what flex means in all the contexts. 我一直在弄弄它一段时间,阅读文档,但我觉得我必须在Material如何决定flex在所有上下文中的含义方面有所遗漏。

Ideally I'd like the div#content to take up the full vertical height, with children aligned at the top. 理想情况下,我希望div#content占据整个垂直高度,并在顶部对齐子级。

Here's the HTML (Jade): 这是HTML(Jade):

div(layout='column', layout-align='center')

  div(layout='row', layout-align='center center')
    div(style='background-color:#00A000; height: 40px;', flex='100', layout-padding='10', layout-padding-left='20')
      div Title

  div(layout='row', layout-align='center center', flex='grow')
    div#content(style='background-color:#EEEEEE;', flex='80', layout-fill)
      div(layout='row',  layout-wrap, layout-align='center center', layout-padding='40', flex='grow')
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) Alpha Beta
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) Gamma
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) Delta
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) Epsilon Rho
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) Eta Zeta
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;'  layout-padding='5', layout-margin="5" ) Theta Iota
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) BBBB
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) CCCC
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) DDDD
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) EEEE
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) FFFF
        div(flex=nogrow, style='background-color:#DDDDDD; width:180px;', layout-padding='5', layout-margin="5" ) GGGG

  div(layout='row', layout-align='center center')
    div(style='background-color:#00A000; height: 40px;', flex='100', layout-padding='10', layout-align="space-around end") Footer

And a screenshot. 和截图。

截图

You don't have to use custom css class for that kind of formating. 您不必使用自定义css类进行这种格式设置。 Check out the following pen. 签出以下笔。 Here in the body(center part) I used md-button instead of your div elements but I'm sure you will be able to repalce it. 在正文(中部),我使用了md-button而不是您的div元素,但是我敢肯定您将能够重新放置它。

http://codepen.io/next1/pen/RapLYY http://codepen.io/next1/pen/RapLYY

I don't think the flex property is appropriate in this case. 在这种情况下,我认为flex属性不合适。 I think what you want is really to set the height to 100% (or similar, like 90% to allow for your header and footer). 我认为您真正想要的是将高度设置为100%(或类似的高度,例如90%,以便保留页眉和页脚)。 In order for that to work, all parent items must have a height set as well though, including html and body. 为了使其正常工作,所有父项也必须设置一个高度,包括html和body。

html, body{ height: 100%; }
#content{ height: 100%; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM