Set vertical scroll on a container with unknown height

后端 未结 1 1216
-上瘾入骨i
-上瘾入骨i 2021-01-26 16:56

Is it possible to set a vertical scroll on a container with unknown height using flexbox?

I can not use max-height as it will limit the hei

相关标签:
1条回答
  • 2021-01-26 17:01

    flex has some short comings/bugs/flaws, or what ever to call them, and need an inner absolute element to force the scroll.

    html, body{
      height: 100%;
      overflow: hidden;
    }
    .list{
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    header {
      flex: 0;
    }
    .vertical {
      flex: 1;
      position: relative;  
    }
    .scroll {  
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      overflow: auto;
    }
    <div class="list flex-vertical">
      <header>Some header</header>
      <div class="vertical">
        <ul class="scroll">
          <li>Item1</li>
          <li>Item2</li>
          <li>Item3</li>
          <li>Item4</li>
          <li>Item5</li>
          <li>Item6</li>
          <li>Item7</li>
          <li>Item8</li>
          <li>Item9</li>
          <li>Item10</li>
          <li>Item11</li>
          <li>Item12</li>
          <li>Item13</li>
          <li>Item14</li>
          <li>Item15</li>
          <li>Item16</li>
          <li>Item17</li>
          <li>Item18</li>
          <li>Item19</li>
          <li>Item20</li>
          <li>Item21</li>
          <li>Item22</li>
          <li>Item23</li>
          <li>Item24</li>
          <li>Item25</li>
          <li>Item26</li>
          <li>Item27</li>
          <li>Item28</li>
        </ul>
      </div>
    </div>

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