我喜欢没有任何滚动条的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;
}
答案 0 :(得分:2)
您应该能够使用flex-grow
属性:
<强> HTML 强>
<div class="wrapper">
<div class="header"></div>
<div class="content">
<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 {
flex-grow: 1;
display: flex;
background: red;
flex-direction: column;
}
.element-child1 {
flex: 0 0 20px;
background-color: blue;
}
.element-child2 {
flex-grow: 1;
background-color: green;
}
<强>替代强>
答案 1 :(得分:0)
CSS
html, body, .wrapper {
width: 100%;
height: 100%;
margin: 0;
padding:0;
}
.wrapper > .header {
height: 40px;
background-color: black;
}
.content {
position:absolute;
top:40px;
bottom:0;
background: red;
width:100%;
}
.element {
height: 100%;
background-color: yellow;
}
.element-child1 {
height: 20px;
background-color: blue;
}
.element-child2 {
background-color: green;
position:absolute;
top:20px;
bottom:0;
width:100%;
}