css - Bootstrap 4 & 全高页面上的 flex 和可折叠内容

标签 css twitter-bootstrap flexbox bootstrap-4

我正在尝试在具有 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,我认为你只需要确保 #resizabledisplay: 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/

相关文章:

css - 基于内容和最小高度的 Flexbox 高度

html - 粗体文本会更改周围文本的对齐方式?

javascript - 使用 jquery 将 html 对象转换为字符串失败

html - 在 Bootstrap 3 导航中删除品牌

jquery - 如何在 bootstrap 工具提示 CSS/Jquery 中提到的文本中使单词变为粗体

html - 沿行对齐图像高度

css - Flexbox 顺序 + CSS 计数器

html - 如何在悬停时使宽度过渡平滑?

html - 打开 Bootstrap 模式时禁用滚动条

html - 使用Bootstrap创建的网站无法正确显示