【问题标题】:FlexBox - Nested div won't fill it's parent when given a height of 100% [duplicate]FlexBox - 当高度为 100% 时,嵌套 div 不会填充它的父级 [重复]
【发布时间】:2020-11-27 05:00:29
【问题描述】:
.container {
  height: 100vh;
  width: 500px;
  border: 1px solid black;
}

.layout {
  display: flex;
  min-height: 100%;
  background-color: blue;
  flex-direction: column;
}

.header {
  height: 50px;
  background-color: orange;
}

.main {
  flex-grow: 1;
  background-color: red;
}

.main-child {
  height: 100%;
  width: 100%;
  background-color: yellow;
}

.footer {
  justify-self: flex-end;
  background-color: purple;
}
<div class="container">
  <div class="layout">
    <header class="header">
      <input/>
    </header>
    <main class="main">
      <div class="main-child">
        <p>
          There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable.
        </p>
        <p>
        My Question, why isn't the yellow part the full size of the red part?
        </p>
      </div>
    </main>
    <footer class="footer">
      <p>
        Texty texty text
      </p>
    </footer>
  </div>
</div>

我的嵌套 div,main-child 的高度为 100%,但它不会填充父 div(它位于 flex 框内,并使用 flex-grow 调整大小)。我希望孩子扩大到其父母的填充大小。

我该如何解决这个问题?

JSFiddle

【问题讨论】:

    标签: javascript html css flexbox


    【解决方案1】:
    .main {
      flex-grow: 1;
      background-color: red;
      display: flex;
    }
    
    .main-child {
      flex: 1;
      width: 100%;
      background-color: yellow;
    }
    

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
    猜你喜欢
    • 2018-01-19
    • 2018-02-07
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多