我有一个div,其中包含可变数量的元素,当内容溢出屏幕的剩余高度时,这些元素应该滚动,但是当内容增长到需要滚动时,div的高度将按照页面标题的精确高度展开.我想这与我的高度/弯曲设置有关,但我很难弄清楚如何防止它增长.

当内容不溢出时,Here是用于页面配置的笔,当内容溢出时,here是笔.

我应该更改什么来防止溢出的内容将div的高度扩展到其父的100%,而使用其父的100%减go header高度?

作为参考,标题大小的大小是由包含在其中的内容确定的,而不是像笔中的固定高度.

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.header {
  width: 100%;
  height: 100px;
  background-color: blue;
  display: flex;
}

.column-container {
  display: flex;
  flex-direction: row;
  background-color: red;
  flex: 1 1 auto;
  height: 100%;
}

.column {
  display: flex;
  flex-direction: column;
  width: 50%;
}

#col-a {
  background-color: green;
}

#col-b {
  background-color: orange;
}

.spacer {
  padding-top: 0px; // Note, change this to force overflow
}

.scroll-area {
  display: flex;
  flex-direction: column;
  overflow: auto;
}
<div class="container">
  <div class="header">
    <p>Header</p>
  </div>
  <div class="column-container">
    <div class="column" id="col-a">
      <p>Column A</p>
      <div class="scroll-area">
        <p>Scroll Area</p>
        <p class="spacer">End</p>
      </div>
    </div>
    <div class="column" id="col-b">
      <p>Column B</p>
    </div>
  </div>
</div>

推荐答案

flex-shrink: 0防止头部收缩. 从.column-container中go 掉height: 100%;由于flex: 1 1 auto,它已经填满了剩余的高度. 此外,给它min-height: 0,以防止它溢出页面.

html, body { 
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.header {
  width: 100%;
  height: 100px;
  background-color: blue;
  display: flex;
  flex-shrink: 0;
}

.column-container {
  display: flex;
  flex-direction: row;
  background-color: red;
  flex: 1 1 auto;
  min-height: 0;
}

.column {
  display: flex;
  flex-grow: 1;
  flex-direction: column;
  height: 100%;
  width: 50%;
}

#col-a {
  background-color: green;
}
#col-b {
  background-color: orange;
}

.spacer {
  padding-top: 0px;
}

.scroll-area {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: auto;
}
<html>
  <body>
    <div class="container">
      <div class="header">
        <p>Header</p>
      </div>
      <div class="column-container">
        <div class="column" id="col-a">
          <p>Column A</p>
          <div class="scroll-area">
            <p>Scroll Area</p>
            <p class="spacer" style="padding-top: 800px">End</p>
          </div>
        </div>
        <div class="column" id="col-b">
          <p>Column B</p>
        </div>
      </div>  
    </div>
  </body>
</html>

Html相关问答推荐

打印pdf时100 vh迪夫有半页高

如何将grid—template—column应用于元素中的子元素

R-markdown中的非顺序列表

我无法从带Angular 的Bootstrap 5中的表单中获取数据

Div中的图像问题-(TailWind CSS中的网格)

Style=背景图像URL引用变成&;Quot;

多次使用组件时计数Angular 14中嵌套数组的指令

UL 的行为就像它不属于任何类别

是否有语义 HTML 可以澄清含义?

为什么 html 元素的 max-width 和 width 一起工作?

并排放置两个 div,同时 div2 环绕 div1

R 中的网页抓取数字?

嵌入最近的 YOUTUBE 视频(不是短片,视频)

如何使背景 colored颜色 逐渐渐变成另一种 colored颜色 ?

如何使容器的大小适合其 position:absolute; 子元素的大小

调整屏幕大小时标题在图像下方重叠 - HTML

如何在图片前面放置下拉框?

如何从另一个 ng-template 获取输入值

从右到左支持百分号

为什么相同持续时间的转换需要不同的时间?