【问题标题】:How to make Bootstrap container auto for height?如何使 Bootstrap 容器自动调整高度?
【发布时间】:2016-02-16 14:41:54
【问题描述】:

我是 JS/CSS 和 Bootstrap 的新手。我对 Bootstrap 的高度有疑问。一般来说,内容太多时,不同的部分会重叠。

我的网页基于 Bootstrap 的封面模板 (https://github.com/twbs/bootstrap/tree/master/docs/examples/cover)。 当我在https://github.com/twbs/bootstrap/blob/master/docs/examples/cover/index.html<div class="inner cover"></div> 块中添加了许多内容时 布局变得可怕而混乱:

虽然正确的布局是:https://getbootstrap.com/examples/cover/

如何使容器高度自动,以便根据内容长度调整高度?感谢您的关注和帮助!

【问题讨论】:

  • 你有没有把header的位置设置为fixed?请为此制作一个jsfiddle。
  • @UmerJaved 感谢您的建议。要做一个jsfiddle。 PS:不仅是页眉,页脚也有问题。
  • @UmerJaved 我制作了 jsfiddle jsfiddle.net/wxgd1mj6。它在小屏幕中正确显示,例如 mobile 和 jsfiddle。但在桌面的大屏幕中,它变得混乱。

标签: html css twitter-bootstrap


【解决方案1】:

看看这个css:

<!-- Custom styles for this template -->
<link href="cover.css" rel="stylesheet">

在这个 .css 中你有这个部分:

/*
 * Affix and center
 */

@media (min-width: 768px) {
  /* Pull out the header and footer */
  .masthead {
    position: fixed;
    top: 0;
  }
  .mastfoot {
    position: fixed;
    bottom: 0;
  }
  /* Start the vertical centering */
  .site-wrapper-inner {
    vertical-align: middle;
  }
  /* Handle the widths */
  .masthead,
  .mastfoot,
  .cover-container {
    width: 100%; /* Must be percentage or pixels for horizontal alignment */
  }
}

@media (min-width: 992px) {
  .masthead,
  .mastfoot,
  .cover-container {
    width: 700px;
  }

所以,对我来说,问题是您的自定义封面样式表不在正确的位置。希望对您有所帮助。

【讨论】:

  • 非常感谢您的回答。我是新手。实际上,我在发布问题之前简要阅读了 css。但是,我不知道问题出在哪里以及如何解决。你能给我一些提示吗?
  • 是的。只需将 cover.css 的内容(在引导示例中)复制到页面的 中,您将获得相同的结果。
  • 有问题!谢谢!然而,问题来了。使用“位置:固定;”,将覆盖包含大量内容的页面。但是没有“位置:固定;”,有一些内容的页面看起来“太平了”。哪些属性可以用来解决它?谢谢!
猜你喜欢
  • 2018-12-21
  • 1970-01-01
  • 2020-02-01
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
  • 1970-01-01
  • 2010-10-17
  • 2021-05-31
相关资源
最近更新 更多