Html 如何获得溢出:在弹性框内滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31292954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:45:06  来源:igfitidea点击:

How can I get overflow:scroll inside a flex box

htmlcssflexbox

提问by Demiurgen

I have built this layout:

我已经建立了这个布局:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<style type="text/css">
html, body{
  margin:0;
  padding:0;
  height:100%;
}
.flex{
  display:flex;
  flex-direction:column;
  min-height:50%;
  width:33.3333%;
  float:left;
  border:1px solid #C8C7CC;
  box-sizing:border-box;
  overflow:scroll;
}
.flex:last-child{
  width:66.6666%;
}
</style>
</head>

<body>
<div class="flex">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
        <li>11</li>
        <li>12</li>
        <li>13</li>
        <li>14</li>
        <li>15</li>
        <li>16</li>
        <li>17</li>
        <li>18</li>
        <li>19</li>
        <li>20</li>
        <li>21</li>
        <li>22</li>
        <li>23</li>
        <li>24</li>
        <li>25</li>
    </ul>
</div>
<div class="flex">

</div>
<div class="flex">

</div>
<div class="flex">

</div>
<div class="flex">

</div>
</body>
</html>

I want to put long lists of things inside each flex box. I need them to scroll individually and at the same time fill all the available space in the browser window. I have managed the latter but how can I get a flex box to scroll instead of grow when overflowed?

我想在每个 flex box 中放入一长串的东西。我需要它们单独滚动,同时填充浏览器窗口中的所有可用空间。我已经管理了后者,但是如何让弹性框在溢出时滚动而不是增长?

采纳答案by Demiurgen

I kept on searching after posting this question and I found this post: Flexbox and vertical scroll in a full-height app using NEWER flexbox api

发布这个问题后我一直在搜索,我找到了这篇文章:Flexbox and vertical scroll in a full-height app using NEWER flexbox api

It suggested setting the parent elements height to 0. I tried it and it seems to be working :D

它建议将父元素高度设置为 0。我试过了,它似乎有效:D