【问题标题】:Full height using flex-direction: column [duplicate]使用 flex-direction 的全高:列 [重复]
【发布时间】:2022-01-30 16:23:25
【问题描述】:

我希望我的 c1 被完全拉伸,但我想知道为什么当我应用 flex:1 时它没有填满空间。

.wrap {
  display:flex;
  flex-direction: column;
}

.c1 {
  background: red;
  flex: 1;
}

.c2 {
  background: blue;
}
<div class='wrap'>
  <div class='c1'>
    <div>child 1</div>
    <div>more content</div>
   </div>
  <div class='c2'>child 2</div>
</div>

【问题讨论】:

  • 需要在父节点上设置高度

标签: html css


【解决方案1】:

在您的包装类中,您必须添加高度。

.wrap {
  display:flex;
  flex-direction: column;
  height: 100vh;
}

.c1 {
  background: red;
  flex: 1;  
}

.c2 {
  background: blue;
}
<div class='wrap'>
  <div class='c1'>
    <div>child 1</div>
    <div>more content</div>
   </div>
  <div class='c2'>child 2</div>
</div>

【讨论】:

  • 高度 100vh 不是我想要的,它会创建滚动条
  • “我希望我的 c1 完全伸展”——你必须定义它是什么。是100vh吗?是 100 像素吗?上面的答案是正确的,只是可能与 100vh 不同。
  • @alice_morgan 您可以随意更改高度,或者您能否更详细地解释您的期望?
  • 我明白了,只需要使用 box-sizing 就可以没有滚动条
猜你喜欢
  • 2019-11-18
  • 2019-08-18
  • 2017-08-03
  • 2019-10-10
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 2019-02-25
  • 1970-01-01
相关资源
最近更新 更多