javascript - 移动 Chrome 栏占用 100% 高度 css 的空间

标签 javascript jquery html css twitter-bootstrap

我面临着一个相当有名的问题,但似乎无法在我的案例中找到任何解决方案。所以我在 bootstrap 上实现了这个可折叠的可滚动条,但问题是当我尝试在移动设备上滚动此条时,由于搜索栏从侧边栏设置的 100% 高度占用了一点空间,滚动条没有到达终点div 的因此剪切了内容。我想知道一种从高度中排除栏的方法,或者想知道解决此问题的解决方法。

这是我的侧边栏 html 和 css:https://jsfiddle.net/fq5b3m1w/

html,
body {
  background: #f8f8f8;
}

#wrapper {
  padding-left: 0;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
  padding-top: 50px;
}

#wrapper.toggled {
  // padding-left: 100px;
}

#sidebar-wrapper {
  z-index: 99999;
  position: fixed;
  left: 100px;
  width: 0;
  height: calc(100%);
  margin-left: -100px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fcfcfc;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}

#wrapper.toggled #sidebar-wrapper {
  width: 100px;
}

#page-content-wrapper {
  width: 100%;
  position: absolute;
  padding: 5px;
  background: #f8f8f8;
}

#wrapper.toggled #page-content-wrapper {
  position: absolute;
  margin-right: -100px;
}


/* Sidebar Styles */

.sidebar-nav {
  position: absolute;
  top: 0;
  width: 100px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-nav li {
  // text-indent: 20px;
  // line-height: 25px;
  text-align: center;
  margin: 0 0;
}

.sidebar-nav li .fa {
  padding-top: 10px;
  display: block;
  // color: rgba(2,136,209,1);
}

.sidebar-nav li.active a {
  // color: #fff;
  background: rgba(2, 136, 209, .2);
}

.sidebar-nav li a {
  display: block;
  text-decoration: none;
  color: #000;
  transition: all .2s;
  font-size: 14px;
  padding: 8px 0;
}

.sidebar-nav li a:hover {
  text-decoration: none;
  color: #333;
  background: rgba(2, 136, 209, 0.2);
}

.sidebar-nav li a:active,
.sidebar-nav li a:focus {
  text-decoration: none;
  color: #333;
  background: rgba(2, 136, 209, 0.2);
}

.sidebar-nav > .sidebar-brand {
  height: 65px;
  font-size: 18px;
  line-height: 60px;
}

.sidebar-nav > .sidebar-brand a {
  color: #999999;
}

.sidebar-nav > .sidebar-brand a:hover {
  color: #fff;
  background: none;
}

@media(min-width:992px) {
  #wrapper {
    padding-left: 100px;
  }
  #wrapper.toggled {
    padding-left: 0;
  }
  #sidebar-wrapper {
    width: 100px;
  }
  #wrapper.toggled #sidebar-wrapper {
    width: 0;
  }
  #page-content-wrapper {
    padding: 20px;
    position: relative;
  }
  #wrapper.toggled #page-content-wrapper {
    position: relative;
    margin-right: 0;
  }
}

最佳答案

第一种方法:

一个简单的解决方案是添加边框以抵消顶部的额外空间

删除:

#wrapper {
    padding-top: 50px;
}

添加:

#sidebar-wrapper {
    border-top: 50px solid white;
}

第二种方法:

创建顶部标题和内容 div,您可以在其中指定标题 height:10% 和内容 height:90%。这样,无论您的尺寸如何,滚动条都将始终适合屏幕。

第三种方法:

使用 display:flex,您可以使用 flex-direction: column; 在列中排列标题和内容。然后使用 flex-basis:50px 和内容指定标题 flex-grow:1flex-basis:auto; 这样内容调整高度本身。

关于javascript - 移动 Chrome 栏占用 100% 高度 css 的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46657607/

相关文章:

javascript - 我可以将 onclick 用于第二个事件吗?

javascript - 如何将 ajax post 从 javascript 发送到 web-api 服务

php - jQuery Ajax 似乎正在 POSTing,但无法捕获值

jquery - 选择器 ID 和功能 : why dont work?

javascript - 有助于为网络实现高分辨率图像、矢量图形的框架

javascript - 在 html5 中文本以视频为中心

html - Bootstrap 表单与搜索表单中的 h1 不对齐

javascript - 在 AngularJs 应用程序中使用 jQuery 插件

javascript - 在 meteor 项目中插入javascript代码: best practice

javascript - 防止 Angular 自定义指令模板中禁用的树节点上的单击事件