仅垂直调整 3 个 div 中的 1 个以适合 window?

Vertically resizing only 1 of 3 divs to fit window?

我正在尝试制作一个应该是简单的响应式页面,它由几个 div 组成,如下所示:

<div id="container"> maximum 1200 width and 1000 height
    <div id="vertically-static-top">20 pixes high</div>
    <div id="vertically-resizeable-middle">adjustable height</div>
    <div id="vertically-static-bottom">50 pixels high</div>
</div>

整体最大宽度和最大高度分别为1200和1000

vertically-static divs 必须仅在浏览器 window 调整大小时水平调整大小,但垂直它们需要始终固定在高度

vertically-resizeable div 需要根据 window 尺寸调整其宽度和高度。

我这辈子都不知道如何让中间的 div 垂直调整大小并将所有内容保留在浏览器中 window!

非常感谢!

这可以通过 flexbox 来实现。这是示例代码:

#container {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical!important;
  -webkit-box-direction: normal!important;
  -ms-flex-direction: column!important;
  flex-direction: column!important;
  height: 240px;
  margin: auto;
  max-height: 1000px;
  max-width: 1200px;
}

#vertically-static-top,
#vertically-static-bottom {
  background-color: #80bdff;
  border-radius: .25rem;
  color: #fff;
  padding: 1rem;
}

#vertically-resizeable-middle {
  background-color: #957bbe;
  border-radius: .25rem;
  color: #fff;
  flex-grow: 1;
  padding: 1rem;
}
<div id="container"> maximum 1200 width and 1000 height
    <div id="vertically-static-top">20 pixes high</div>
    <div id="vertically-resizeable-middle">adjustable height</div>
    <div id="vertically-static-bottom">50 pixels high</div>
</div>

调整#container (height: 240px;) 的高度或将 100% 改为适合父元素的高度

我认为你必须使用位置 absolute。检查以下代码段。

html,
body {
  font: 13px Verdana;
  margin: 0;
  height: 100%;
}

#container {
  max-height: 1000px;
  max-width: 1200px;
  background: red;
  color: #fff;
  height: 100%;
  position: relative;
}

#vertically-static-top,
#vertically-static-bottom,
#vertically-resizeable-middle {
  position: absolute;
  left: 0;
  right: 0;
}

#vertically-static-top {
  height: 20px;
  top: 0;
  background: black;
}

#vertically-static-bottom {
  height: 50px;
  bottom: 0;
  background: black;
}

#vertically-resizeable-middle {
  top: 20px;
  bottom: 50px;
}
<div id="container">
  <div id="vertically-static-top">20 pixes high</div>
  <div id="vertically-resizeable-middle">adjustable height</div>
  <div id="vertically-static-bottom">50 pixels high</div>
</div>

我希望这会奏效。