我有两个独立滚动的 div,一个带有页眉和页脚。
<body>
<div class="container col-1">
Many listings
</div>
<div class="container col-2">
<div class="header">Fixed Header</div>
<div class="content">Lots of content</div>
<div class="footer">Fixed footer</div>
</div>
</body>
请参阅此 fiddle :https://jsfiddle.net/bhmvv05n/
问题是,我希望第二个容器 div 有一个固定的页眉和页脚,它们始终可见并且只有内容可滚动。
一旦我更改了 col-2
div 的滚动,两列就不再独立滚动了。
有什么建议吗?
谢谢!
最佳答案
这将根据您为列设置的任何宽度
进行调整。
这个想法是您只使 .col-2.content
可滚动,而不是整个 .container
。
* {
box-sizing: border-box;
}
html, body {
margin: 0;
height: 100%;
}
.container {
height: 100%;
}
.col-1{
float: left;
width: 33%;
overflow: auto;
}
.col-2{
float: left;
width: 67%;
position: relative;
}
.col-2 .content {
position: absolute;
left: 0; right: 0;
top: 20px; /* header height */
bottom: 20px; /* footer height */
overflow: auto;
}
.header, .footer {
height: 20px;
background-color: red;
position: absolute;
left: 0; right: 0;
}
.header {
top: 0;
}
.footer {
bottom: 0;
}
关于html - 独立滚动的 div,一个带有固定的页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37398578/