One div dynamic height one div remaining height and scroll

后端 未结 1 1319
野的像风
野的像风 2021-01-22 07:39

I have 2 divs inside a parent:

相关标签:
1条回答
  • 2021-01-22 08:02

    You can either use flexbox. no markup changes.

    .parent {
      display: flex;
      flex-direction: column;
      height: 100px;
    }
    .foo2 {
      flex: 1; /*expand to fit*/
      background: silver;
      overflow: auto; /*scroll as needed*/
    }
    <div class="parent">
      <div class="foo1">1</div>
      <div class="foo2">2<br>2<br>2<br>2<br>2<br>2<br>2<br>2</div>
    </div>

    Or use CSS table, additional markup is required.

    .parent {
      display: table;
      width: 100%;
      height: 100px;
    }
    .foo1, .foo2 {
      display: table-row;
    }
    .cell {
      display: table-cell;
      position: relative;
    }
    .foo2 {
      height: 100%; /*expand to fit*/
      background: silver;
    }
    .scroll {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      overflow: auto; /*scroll as needed*/
    }
    <div class="parent">
      <div class="foo1">
        <div class="cell">1</div>
      </div>
      <div class="foo2">
        <div class="cell">
          <div class="scroll">2<br>2<br>2<br>2<br>2<br>2<br>2<br>2</div>
        </div>
      </div>
    </div>

    0 讨论(0)
提交回复
热议问题