【问题标题】:Bootstrap 4 & flex and collapsible content on full-height pageBootstrap 4 & flex 和全高页面上的可折叠内容
【发布时间】:2020-12-03 20:11:10
【问题描述】:

我正在尝试在带有 flex 和 bootstrap 4 的全高页面上使用可折叠的 div(固定高度)(与 bootstrap 3 相同的问题)。

当前的 sn-p 在 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>

【问题讨论】:

    标签: css twitter-bootstrap flexbox bootstrap-4


    【解决方案1】:

    对于 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-08
      • 2019-07-10
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2012-05-16
      相关资源
      最近更新 更多