【发布时间】:2014-04-23 22:12:43
【问题描述】:
我喜欢没有任何滚动条的 100% 高度。在我的示例中,浏览器似乎计算了整个高度。子元素如何获得父元素的 100% 高度。
html
<div class="wrapper">
<div class="header"></div> //<- Here is the problem
<div class="content">
<div class="element">
<div class="element-child1"></div>
<div class="element-child2"></div>
</div>
<div/>
css
html, body, .wrapper {
width: 100%;
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
}
.wrapper > .header {
flex: 0 0 40px;
background-color: black;
}
.wrapper > .content {
align-self: stretch;
flex: 1;
background: red;
}
.element {
align-self: stretch;
display: flex;
flex-direction: column;
background-color: yellow;
}
.element-child1 {
flex: 0 0 20px;
background-color: blue;
}
.element-child2 {
flex: 1;
background-color: green;
}
【问题讨论】: