【问题标题】:How do I make my panel to fill the screen down to the footer?如何使我的面板将屏幕填充到页脚?
【发布时间】:2018-06-06 12:08:38
【问题描述】:

我希望我的面板占据整个屏幕,直到页脚,即使面板是空的。 如果面板已填满,我想滚动查看内容,但页脚应始终在页面底部可见。 你有想法吗? 这是代码:

.list_mobile .footer {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 60px;
  background: lightskyblue;
  color: darkred;
}
<div class="row">
  <div class="col-xs-12 col-sm-12 col-lg-12 mg-tp-xs">
    <div class="panel panel-danger" style="overflow :scroll">
      <div class="panel-heading">
        <h4 class="panel-title">
          <span>Result</span>
        </h4>
      </div>
      <div class="panel-collapse">
        <div class="panel-body">
          <p>test</p>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="list_mobile">
  <footer class="footer">
    <div class="container">
      <h4>number of results : 55 </h4>
    </div>
  </footer>
</div>

【问题讨论】:

    标签: html css bootstrap-4


    【解决方案1】:

    Bootstrap 已删除 *-xs-* 类的所有变体。而不是col-xs-12,使用col-12。由于所有尺寸的列都是 100%,因此使用 col-12 就足够了。


    1. 使用 d-flex flex-column h-100 作为行的父级。
    2. 对行使用 flex-grow-1
    3. 所有行的父级必须具有 100% 的高度,包括正文和 html。
    4. col-12panel 的高度必须为 100%
    5. 使用 row 作为页脚。
    6. 不要改变footer的位置:删除position: absolute; bottom: 0;right: 0;

    html,
    body {
      height: 100%;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
    <div class="container-fluid d-flex flex-column h-100 bg-primary">
      <div class="row flex-grow-1">
        <div class="col-12  bg-danger h-100">
          <div class="panel panel-danger h-100">
            <div class="panel-heading">
              <h4 class="panel-title">
                <span>Result</span>
              </h4>
            </div>
            <div class="panel-collapse">
              <div class="panel-body">
                <p>test</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    
      <div class="row">
        <footer class="col-12 footer">
          <div class="container">
            <h4>number of results : 55 </h4>
          </div>
        </footer>
      </div>
    </div>

    您可以使用container 代替container-fluid。它没有任何区别。如果这样做,请购买,删除页脚中的容器。

    html,
    body {
      height: 100%;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
    <div class="container d-flex flex-column h-100 bg-primary">
      <div class="row flex-grow-1">
        <div class="col-12  bg-danger h-100">
          <div class="panel panel-danger h-100">
            <div class="panel-heading">
              <h4 class="panel-title">
                <span>Result</span>
              </h4>
            </div>
            <div class="panel-collapse">
              <div class="panel-body">
                <p>test</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    
      <div class="row">
        <footer class="col-12 footer">
            <h4>number of results : 55 </h4>
        </footer>
      </div>
    </div>

    【讨论】:

    • 页脚现在“卡”在面板上,但面板并没有占据页面的所有高度,我在 css 上使用错误,我在哪里写 html, body { height: 100%; } ?
    • 在您的自定义 CSS 文件中。您还可以将h-100 类用于htmlbody
    • @SendoTks 没有用吗?如果不是,那是什么问题?
    • 面板没有填充到页脚,有时结果太多,它在页脚下,我什么都看不到,所以我尝试了其他方法。看这里:@ 987654321@我已经尝试在新帖子中要求更清楚,但我认为我这样做是错误的,因为它是重复的,我很抱歉,我可以删除重复的帖子它只会被否决?
    • @SendoTks 你做错了。在此问题中添加所有代码,包括 bodyhtml。我去看看。
    猜你喜欢
    • 2014-03-26
    • 1970-01-01
    • 2013-11-19
    • 2011-08-13
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    相关资源
    最近更新 更多