使用overlayScrollbars.js

时间:2018-06-18 15:23:06

标签: jquery css

我遇到overlayScrollbars的问题。

我有一个简单的布局,固定左面板和页脚,可调整大小(和可滚动)内容。

Bare bones css正常工作正常:CodePen1

但是当我尝试添加overlayScrollbars来设置滚动条的样式时,内容div宽度会崩溃:CodePen2

任何想法如何解决这个问题?

HTML

<div id="panel"></div>

<div id="content">
  <div class="container">
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
  </div>
</div>

<div id="footer"></div>

CSS

html, body {
  height:100%;
  margin: 0;
  padding: 0;
  color: #808080;
  font-family: arial;
  line-height: 1.5rem;
}

#panel {
  float: left;
  left: 0;
  width: 255px;
  background: #F1F1F1;
  box-sizing: border-box;
  display: block;
  height: 100%;
  position: fixed;
}

#content {
  width: auto;   
  float: left;
  margin-left: 255px;
  position: fixed;
  box-sizing: border-box;
  height: 100%;
  overflow-x: auto;
}

#footer {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 70px;
  width: 100%;
  box-sizing: border-box;
  display: block;
  background: #F1F1F1;
}

.container {
  position: relative;
  padding: 20px 20px 90px 20px;
  box-sizing: border-box;
}

注意 - 我省略了内联JS&amp;包含在笔中的overlayScrollbars的CSS(没有可用的CDN)。

1 个答案:

答案 0 :(得分:1)

原来是float div中的position#content属性。 删除它们然后将z-index添加到#footer div修复它。

Working Codepen

#content {
  width: auto;   
  margin-left: 255px;
  box-sizing: border-box;
  height: 100%;
  overflow-x: auto;
}

#footer {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 70px;
  width: 100%;
  box-sizing: border-box;
  display: block;
  background: #F1F1F1;
  z-index: 10;
}