我遇到了 overlayScrollbars 的问题.
我有一个简单的布局、固定的左侧面板和页脚,内容可调整大小(和可滚动)。
基本的 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;
}
注意 - 我省略了笔中包含的 overlayScrollbars 的内联 JS 和 CSS(没有可用的 CDN)。
最佳答案
原来是 #content
div 中的 float
和 position
属性。
删除它们,然后将 z-index
添加到 #footer
div 修复它。
#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;
}
关于jquery - 使用 overlayScrollbars.js 时 div 宽度自动折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50912752/