我们如何缩小中间的弹性项目?

How can we shrink middle flex item?

我正在尝试从 flexbox 进行布局。我有 3 列框,它们具有以下布局,直到它们到达移动布局,它们将堆叠在另一个布局之上。 但在我到达移动布局之前,我试图按比例缩小所有项目。 (即当我减少浏览器宽度时,它应该同样小)。但只有 leftright 项除中间项外均等减少。我该如何缩小,以便所有项目按比例缩小,同时减小浏览器宽度?

代码在这里

.container {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 80px;
}

.box {
  width: 400px;
  /*   min-width: 280px; */
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid black;
  font-size: 30px;
  font-weight: bold;
  font-family: cursive;
  box-shadow: 1px 4px 3px rgba(0, 0, 0, 0.5);
}
.box1 {
  background: grey;
}
.box2 {
  background: green;
  margin-bottom: 20px;
}
.box3 {
  background: greenyellow;
}
.box4 {
  background: orange;
}
.middle-part {
  margin: 0px 20px;
  /*   min-width: 280px; */
}
<div class="container">
  <div class="box box1">
    I am box1
  </div>
  <div class="middle-part">
    <div class="box box2">
      I am box2
    </div>
    <div class="box box3">
      I am box3
    </div>
  </div>
  <div class="box box4">
    I am box4
  </div>
</div>

如果你想让它动态收缩,你需要去掉宽度设置。在 .box.middle-part 上添加 flex-grow: 1 以使其增长。此外,padding-top 只接受 1 个值,因此可能存在一些拼写错误。

.container {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 80px 40px; /* padding top only accept 1 value */
}
.middle-part {
  flex-grow: 1;
}
.box {
  flex-grow: 1;
  /*   min-width: 280px; */
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid black;
  font-size: 30px;
  font-weight: bold;
  font-family: cursive;
  box-shadow: 1px 4px 3px rgba(0, 0, 0, 0.5);
}
.box1 {
  background: grey;
}
.box2 {
  background: green;
  margin-bottom: 20px;
}
.box3 {
  background: greenyellow;
}
.box4 {
  background: orange;
}
.middle-part {
  margin: 0px 20px;
  /*   min-width: 280px; */
}
<body>
  <div class="container">
    <div class="box box1">
      I am box1
    </div>
    <div class="middle-part">
      <div class="box box2">
        I am box2
      </div>
      <div class="box box3">
        I am box3
      </div>
    </div>
    <div class="box box4">
      I am box4
    </div>
  </div>
</body>