无法在 flex child 上将高度设置为 100%

Can't set height to 100% on flex child

我有一个相当直接的布局,这涉及到我的 body(基本上是 header 之后的页面内容)至少为 100% 高度。这在桌面断点上工作正常,但一旦我切换到移动断点(将容器设置为 flex-direction 到列),我似乎无法使 body 元素 100% 高度。我试过使用 100vh,它确实有效,但随后搞砸了桌面视图的布局。此 body 元素的每个 parent 的高度都大于 it/100%。

我正在使用 flexbox、styled-components 和 React。

有什么想法吗?谢谢!

Body CSS:

  font-family: 'FuturaBold';
  box-sizing:border-box;
  color: black;

  height: 100%;

  display: flex;
  flex-direction: column;

  @media (max-width: ${Breakpoints.tablet}) {
    padding-top: 50px;
  }

Parent CSS:

  min-height: 100% !important;
  box-sizing: border-box;

  background-color: ${Colours.dark};

  display: flex;

  @media (max-width: ${Breakpoints.tablet}) {
    flex-direction: column;
  }

Picture here

结合您的方法。

仅在媒体查询中设置height: 100vh。这不会在桌面视图中搞砸