标题 div 保持在顶部,垂直滚动 div 下方,滚动条仅附加到该 div

Header div stays at top, vertical scrolling div below with scrollbar only attached to that div(标题 div 保持在顶部,垂直滚动 div 下方,滚动条仅附加到该 div)
本文介绍了标题 div 保持在顶部,垂直滚动 div 下方,滚动条仅附加到该 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有 2 个主要的 div,标题和一个包含在 div 中的滚动列表.我希望标题始终保留在页面顶部,以及下面的滚动列表.滚动条应该附加到滚动的div而不是整个页面,即滚动条不会出现在标题的右侧,只是滚动的div.

I have 2 main divs, the header and a scrolling list contained in a div. I want the header to always remain at the top of the page, and the scrolling list below. The scrollbar should be attached to the scrolling div and not to the whole page, i.e. the scrollbar does not appear on the right of the header, just the scrolling div.

这就是我想要实现的目标:

This is what i'm trying to achieve:

______________________
|_______header_______|
|                  |*|
|   Container Div  |*|
|                  |*|
|                  |*|
|                  |*|
|                  |*|
|                  |*|
----------------------

* = scrollbar

布局应该是流畅的,如果窗口垂直拉伸,只有容器 div 和它的滚动条应该变长.

The layout should be fluid and if the window is stretched vertically, only the container div and it's scrollbar should get longer.

我不想将标题 position: fixed; 放置在这样的位置,因为滚动条将位于它的右侧而不是它的下方.

I don't want to position the header position: fixed; as then the scrollbar will be on the right of it instead of underneath it.

推荐答案

HTML:

<div class="header">This is the header</div>
<div class="content">This is the content</div>

CSS:

.header
{
    height:50px;
}
.content
{
    position:absolute;
    top: 50px;
    left:0px;
    right:0px;
    bottom:0px;
    overflow-y:scroll;        
}

这篇关于标题 div 保持在顶部,垂直滚动 div 下方,滚动条仅附加到该 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Scale background image to fit ie8 window(缩放背景图像以适合 ie8 窗口)
@fontface in IE7 (IETEster) not working properly(IE7 (IETEster) 中的@fontface 无法正常工作)
Safari 5.1 breaks CSS table cell spacing(Safari 5.1 打破 CSS 表格单元格间距)
How to delegate `hover()` function by using `on()`(如何使用 `on()` 委托 `hover()` 函数)
How to center slider in css?(如何在css中居中滑块?)
Show slider range value on top of thumb(在拇指顶部显示滑块范围值)