html - 当 parent 没有更多的成长空间时如何使 child 滚动

标签 html css

enter image description here

这是我的尝试: http://jsbin.com/xokidev/7/edit?html,output

  <phone style="
    display:block;
    position:relative; 
    margin:auto; 
    width:300px; 
    height:500px;
    background:silver;
    overflow:hidden">
    <navigation-or-something style="
      display:block;
      position:absolute;
      height:100px; 
      width:100%;
      background:skyblue">
      known height. don't overlap
    </navigation-or-something>
    <component style="
      position: absolute; 
      right:0;
      bottom:0;
      left:0; 
      max-height: calc(100% - 100px); 
      display:block;">
      <header style="background:yellow">
        multiline variable text height. multiline variable text height
      </header>
      <container style="
        display:block; 
        background: pink; 
        overflow-y:auto;">
        <content>
          some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. 
        </content>
      </container>
    </component>
  </phone>

您会发现的问题是,一旦父级没有更多的增长空间,我的粉红色子级就不会开始滚动。

最佳答案

使用 display: flex;flex-direction: column; 让它只滚动粉色部分

<phone style="
    display:block;
    position:relative; 
    margin:auto; 
    width:300px; 
    height:500px;
    background:silver;
    overflow:hidden">
  <navigation-or-something style="
      display:block;
      position:absolute;
      height:100px; 
      width:100%;
      background:skyblue">
    known height. don't overlap
  </navigation-or-something>
  <component style="
      position: absolute; 
      right:0;
      bottom:0;
      left:0; 
      max-height: calc(100% - 100px); 
display: flex;
flex-direction: column;">
    <header style="background:yellow">
      multiline variable text height. multiline variable text height
    </header>
    <container style="
        display:block; 
        background: pink;
        overflow-y:auto;">
      <content>
        some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable
        height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height
        content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content.
        some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some
        variable height content. some variable height content. some variable height content. some variable height content. some variable height content. some variable height content.
      </content>
    </container>
  </component>
</phone>

关于html - 当 parent 没有更多的成长空间时如何使 child 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41348999/

相关文章:

javascript - 从输入值中删除单击的 id

html - 各行的 CSS 背景颜色

html - 我怎样才能得到溢出:scroll inside a flex box

javascript - 预览图像 Jquery 脚本运行不正常

php - 从左到右而不是从上到下使用多列 css

html - 图像悬停的猫头鹰轮播 div 高度

javascript - 仅当指定对象在页面上时才运行脚本

javascript - 使用 webpack 将所有部分放在一起

css - 本地托管的 Google 字体未加载

CSS::焦点:之前不起作用