fixed header div with scrollable div below

后端 未结 3 1766
滥情空心
滥情空心 2021-01-19 13:15

I\'m trying to place two divs one above the other. The top one has a fixed size. The bottom one needs to fill the rest of the page height, without making the page higher if

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 13:49

    In case if anyone wants to solve this keeping things in normal flow, nowadays this can be done using the flexbox layout model as shown below:

    * {
      margin: 0;
      padding: 0;
    }
    html,
    body {
      height: 100%;
    }
    #content {
      display: flex;
      flex-direction: column;
      width: 300px;
      height: 100%;
      margin: 0 auto;
      background-color: #C9E6FF;
    }
    #top-padding {
      height: 30px;
      flex: none;
      background: blue;
    }
    #stuff {
      flex: auto;
      overflow-y: auto;
      background-color: lightgreen;
    }
    /*for demo purpose */
    
    #stuff p {
      height: 1000px;
    }

    some content

提交回复
热议问题