2017-01-05 80 views
1

试图将空状态置于app-header以下。我希望它占据整个屏幕的全宽和全高(减去app-header的高度)。全宽度和高度空状态?

到目前为止,我有这个,但它似乎并没有工作:

<app-header-layout> 
    <app-header> 
     ..... 
    </app-header> 
    <div id="empty-state" style="width: 100%; height: 100%; background: #F00; white-space: nowrap;"> 
     ..... 
    </div> 
</app-header-layout> 

仍然没有去。空状态具有我想要的全部宽度,但不是我想要的高度。

请帮我一把。

+0

参见[这个问题](http://stackoverflow.com/questions/90178/make-a-div-fill-the-height-of-the-remaining -screen空间) – chester

回答

0

有一些方法可以做到这一点。您可以使用flex-box(解释here):

body, 
 
html { 
 
    height: 100%; 
 
} 
 
body { 
 
    margin: 0px; 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 
app-header { 
 
    min-height: 50px; 
 
} 
 
#empty-state { 
 
    overflow: auto; 
 
    background: #F00; 
 
    flex-grow: 1; 
 
    overflow: auto; 
 
}
<body> 
 
    <app-header>...</app-header> 
 
    <div id="empty-state"> 
 
    ..... 
 
    </div> 
 
</body>

你也可以简单地进行绝对定位的元素。简单地说明app-header的高度和偏移#空状态的高度。就像这样:

body, 
 
html { 
 
    height: 100%; 
 
} 
 
body { 
 
    margin: 0; 
 
} 
 
app-header { 
 
    width: 100%; 
 
    height: 50px; 
 
} 
 
#empty-state { 
 
    position: absolute; 
 
    top: 50px; 
 
    bottom: 0; 
 
    background: #F00; 
 
    width: 100%; 
 
}
<app-header-layout> 
 
    <app-header> 
 
    ..... 
 
    </app-header> 
 
    <div id="empty-state"> 
 
    ..... 
 
    </div> 
 
</app-header-layout>