简体   繁体   English

如何使用 css 独立滚动两个 div

[英]how to scroll two divs independently using css

I have a page layout at the link below.我在下面的链接中有一个页面布局。 when i scroll the inner-window area both the divs are scrolling..当我滚动内部窗口区域时,两个 div 都在滚动..

Link to code链接到代码

I want two divs(first-column, second-column) inside inner-window to scroll independently.我希望内部窗口内的两个 div(第一列,第二列)独立滚动。 And disable scroll if the content is within the view port height.如果内容在视口高度内,则禁用滚动。 Is that possible to do with just CSS?这可能与 CSS 有关吗?

I haven't tried it out, but I'd try setting overflow-y: scroll in the CSS file for each div.我还没有尝试过,但我会尝试设置overflow-y: scroll That should automatically add scroll functionality when the content height exceeds the div height (assuming you have a fixed height set).当内容高度超过 div 高度时(假设您设置了固定高度),这应该会自动添加滚动功能。 If it doesn't work, feel free to let me know.如果它不起作用,请随时让我知道。 Good luck!祝你好运!

Add scroll to independent class and also you have to set at what max height you want the content to have scroll, for the example below I have used 400px as the height, post that height you will have scroll.将滚动添加到独立的 class 并且您必须设置您希望内容滚动的max高度,对于下面的示例,我使用400px作为高度,发布您将滚动的高度。

Bonus tip奖金提示

When using flex for direction, flex-direction:row;当使用flex作为方向时, flex-direction:row; is default you no need to specifically use that.默认情况下,您无需专门使用它。

 .fixed-box { position: fixed; width: 100%; }.sticky-header { position: fixed; }.inner-window { border: 1px solid red; display: flex; flex-direction: row; }.first-column { overflow-y: auto; height: 400px; }.second-column { overflow-y: auto; height: 400px; }
 <div class="row h-100"> <div class="col-3"> <div class="col-9 bg-warning h-100 right-window"> <div class="inner-window"> <div class="first-column"> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> <p>This is first column</p> </div> <div style="background: green" class="second-column"> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> <p>This is second column</p> </div> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM