twitter-bootstrap 带侧边栏的 Bootstrap 完全 100% 高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18601135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 18:14:32  来源:igfitidea点击:

Bootstrap fully 100% height with a sidebar

htmlcsstwitter-bootstrapheightsidebar

提问by Konstantin Rusanov

I can not understand why is it that the height of the sidebar on the right, not 100%, and when I scroll down the page, the background is interrupted.

我不明白为什么右侧边栏的高度不是100%,当我向下滚动页面时,背景被中断。

<nav id="nav" class="nav-primary hidden-xs nav-vertical">
<ul class="nav affix-top" data-spy="affix" data-offset-top="50">
<li><a href=""><i class="icon-user"></i> Профиль</a></li>
<li><a href=""><i class="icon-bar-chart"></i> Финансы</a></li>
<li><a href=""><i class="icon-sitemap"></i> Товары</a></li>
<li><a href=""><i class="icon-signal"></i> Товары (статистика)</a></li>
<li><a href=""><i class="icon-envelope-alt"></i> Уведомления (10)</a></li>
</ul>
</nav>

enter image description here

在此处输入图片说明

Life example here

生活例子在这里

回答by Jacques ジャック

A couple things.

一些事情。

  1. You have two positionproperties set in your CSS for the #nav.
  2. You should have only one, and it should be position:fixed
  3. There is no need for top: 0; left: 0AND bottom: 0;If the object is 100% height and fixed to the top left, it will always touch the bottom.
  1. position在 CSS 中为#nav.
  2. 你应该只有一个,而且应该是 position:fixed
  3. 不需要top: 0; left: 0ANDbottom: 0;如果对象是 100% 的高度并且固定在左上角,它会一直接触到底部。

CSS should be:

CSS 应该是:

#nav {
  position:fixed;
  width: 200px;
  z-index: 1000;
  left: 0;
  top: 0;
  border-right: 1px solid #162636;
  height: 100%;
}

回答by heidi

The height of the sidebar is 100%, however, when you scroll down the page, the height of the page becomes more than 100%. The sidebar's height won't increase to match the page's height. Thus, changing the sidebar's positionproperty to position:fixedcould help.

侧边栏的高度是 100%,但是,当您向下滚动页面时,页面的高度会超过 100%。侧边栏的高度不会增加以匹配页面的高度。因此,将侧边栏的position属性更改为position:fixed可能会有所帮助。