我正在尝试在具有 flex 和 bootstrap 4(与 bootstrap 3 相同的问题)的全高页面上有一个可折叠的 div
(固定高度)。
当前代码片段在 Firefox 上运行良好,但在基于 Chrome 的浏览器上不起作用:collapsable
的初始大小是正确的 (100px
),但是一旦您折叠它,它不会正确调整大小(0px
如果 subresizable 的高度是 100%
,或者与可用空间成比例)。
html, body {
height:100%;
width: 100%;
}
body {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-flow: column;
}
#collapsable {
height: 100px;
background-color: green;
}
#subresizable {
height: 100%;
width: 100%;
background-color: pink;
}
#resizable {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
background-color: red;
}
<header>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</header>
<body>
<div id="resizable">
<div id="subresizable">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapsable" aria-expanded="false" aria-controls="collapsable">COLLAPSE</button>
</div>
</div>
<div id="collapsable" class="collapse in"></div>
</body>
最佳答案
对于 Bootstrap 3,我认为你只需要确保 #resizable
是 display: flex;
#resizable {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
background-color: red;
display: flex;
}
http://codeply.com/go/DcioXI4Xwl
在 Bootstrap 4 中,您可以只使用 d-flex
util 类。
相关问题:Show/Hide div in Bootstrap 4 while resizing height of leaflet map
关于css - Bootstrap 4 & 全高页面上的 flex 和可折叠内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42467327/