制作一个可滚动的div,它不会滚动身体的其余部分
16lz
2021-01-22
Should be simple but I can't work it out.
应该很简单,但我无法解决。
I have two panes on my webpage. I want both to be independently scrollable:
我的网页上有两个窗格。我希望两者都可以独立滚动:
<body>
<div id="sidebar"> ... lots of content ... </div>
<div id="container"> ... lots of content ... </div>
</body>
#sidebar{
width:200px;
position:fixed;
overflow:scroll;
background-color:black;
color:white;
top:0;
left:0;
height:100%;
}
Here is a JSFiddle. Notice how when you scroll to the bottom in the black sidebar, and keep scrolling, the body starts to scroll? That's what I want to avoid. Is there a simple way to achieve this?
这是一个JSFiddle。注意当你滚动到黑色侧边栏的底部,并继续滚动时,身体开始滚动?这就是我想要避免的。有没有一种简单的方法来实现这一目标?
4 个解决方案
#1
0
Please try following updated CSS. Here I have set 200px height after that it will add scroll bar for #sidebar div.
请尝试关注更新的CSS。在这里我设置了200px的高度,之后它会为#sidebar div添加滚动条。
#sidebar{
width:200px;
position:fixed;
overflow:auto;
background-color:black;
color:white;
top:0;
left:0;
height:200px;
}
Hope it may help.!!
希望它可能有所帮助。!!
更多相关文章
- 如何在HTML主体上设置网格ExtJS,高度为100%
- 让列在3列CSS布局中扩展到相同的高度?
- 纯CSS最小化高度标题,绝对定位DIV内最大化身高
- CSS Transition div容器高度从100%到200%
- 保持子div的宽高比与父级的高度和宽度变化
- 自动设置绝对子级的父div的高度
- 浮动到页面底部的可变高度页脚的CSS(不是视口)
- 100%高度分区内显示:表格单元分区
- JQuery基于元素的高度添加类