One div dynamic height one div remaining height and scroll

后端 未结 1 1320
野的像风
野的像风 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*/
    }
    1
    2
    2
    2
    2
    2
    2
    2
    2

    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*/
    }
    1
    2
    2
    2
    2
    2
    2
    2
    2

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