html - 独立滚动的 div,一个带有固定的页眉和页脚

标签 html css

我有两个独立滚动的 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/

相关文章:

javascript - 使用 D3 将多个图表添加到一页

javascript - 在 document.getElementById ('' ).innerHTML = 之后放置链接

html - 输入为空时如何隐藏部分css?

javascript - 非对称 Bootstrap 布局

javascript - 第一个动画完成后调用第二个动画

javascript - 使用 AngularJS 访问另一个函数的变量

css - ng-repeat 的 Angular 动画不起作用

javascript - 如何使主体在 ScrollDown 上向左滚动,反之亦然

javascript - 等距游戏 - 假视口(viewport)运动问题

CSS Sprite 生成器 : I have the bundled image