高度 100% 弯曲

arp*_*gie 3 html css flexbox

我想让内容 div 适合 100% 高度。由于某种原因,容器 div 恰好是一个弹性项目。将 Flex 项目中的 div 设置为 100% 高度是否合适?或者我也应该将内容 div 设置为弹性项目。

另外,弯曲方向部分也令人困惑。列不起作用,但行起作用。我想 flex-direction 只对弹性项目有影响。

jsfiddle在这里

<div class="wrapper">
  <div class="container">
    <div class="content">
      Hello there
    </div>
  </div>
</div>


html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.wrapper {
  border: 1px solid red;
  padding: 20px;
  min-height: 100%;
  display: flex;
  /* change flex-direction from column to row will work */
  flex-direction: column;
}

.container {
  border: 1px solid green;
  padding: 20px;
  flex: 1;
}

.content {
  border: 1px solid blue;
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)

G-C*_*Cyr 5

您可以重叠(嵌套)弹性框:

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.wrapper {
  border: 1px solid red;
  padding: 20px;
  min-height: 100%;
  display: flex;
  /* change flex-direction from column to row will work */
  flex-direction: column;
  box-sizing:border-box;
}

.container {
  display:flex;
  flex-direction: column;/* up to your needs */
  border: 1px solid green;
  padding: 20px;
  flex: 1;
}

.content {
  border: 1px solid blue;
  flex:1;
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
  <div class="container">
    <div class="content">
      Hello there
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

您可能还介意框大小属性在大小计算中包括边框和填充。