为什么 Flex 和 max-height vh 工作不正确?

Why Flex and max-height vh work not correct?

我有 flex 个容器。我的弹性容器中有 rightleft 弹性元素。

我的问题:左右方块的高度不同。 例如:

.container {
  display: flex;
  width: 100%;
  max-height: calc(100vh - 50px);
  overflow-y: auto;
  background: #fff;
}

.left {
  width: 200px
}

.right {
  width: calc(100% - 200px);
  background: #000;
}
<div class="container">
  <div class="left">
    "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
  </div>
  <div class="right"></div>
</div>

而且我不明白为什么我右边的方块没有高度 - 100%。 我该如何解决?我想要右方块和左方块高度相同。

元素高度相同但垂直尺寸较小,左边的 溢出

如果 max-height 很重要,请将其放在子 div 上。

.container {
  display: flex;
  background: #fff;
}

.container div {
  max-height: calc(100vh - 50px);
  overflow-y: auto;
}

.left {
  width: 200px;
  background: lightgrey;
   
}

.right {
  width: calc(100% - 200px);
  background: #000;
}
<div class="container">
  <div class="left">
    "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human
    happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues
    or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except
    to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
  </div>
  <div class="right"></div>
</div>

为您的元素添加 +1 容器

.container {
  max-height: calc(100vh - 50px);
}

.flex {
  display: flex;
  width: 100%;
  overflow-y: auto;
  background: #fff;
}

.left {
  width: 200px;
}

.right {
  width: calc(100% - 200px);
  background: #000;
}
<div class="container">
  <div class="flex">
    <div class="left">
    "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
  </div>
  <div class="right"></div>
  </div>
</div>