简体   繁体   English

如何在不使用框架的情况下,允许页面上2 DIV的内容独立向下或向上滚动?

[英]How to allow the content of 2 DIV side by side of a page to be scroll down or up independently without using frames?

I have an page written in ASP classic that uses frameset containing 2 frames. 我有一个用ASP经典编写的页面,该页面使用包含2个框架的框架集 While the left frame serve to display the menu, the right frame display the page content. 左框架显示菜单时,右框架显示页面内容。

The way the page works, user can independently scroll down or up content of either one of the frames. 页面的工作方式,用户可以独立向下或向上滚动任一框架的内容。

How can I reproduce the same functionality using only HTML and CSS? 如何仅使用HTML和CSS复制相同的功能?

<div id="menu-container">
  //menu goes here...
</div>
<div id="main-content">
  //main content here...
</div>

Thanks for helping 感谢您的帮助

Give each a fixed height like 500px; 给每个固定高度,例如500px;

Then set the overflow-y property to auto or scroll to enable the scrollbar 然后将overflow-y属性设置为auto或scroll以启用滚动条

overflow-y: auto;

here is a working fiddle: 这是一个工作的小提琴:

https://jsfiddle.net/pablo_tavarez/dobza7gv/1/ https://jsfiddle.net/pablo_tavarez/dobza7gv/1/

You can do this with overflow: auto and fixed height on parent element. 您可以通过以下方式做到这一点overflow: auto父元素的overflow: auto height和固定height

 body, html { margin: 0; padding: 0; } .content { height: 100vh; display: flex; } .left, .right { flex: 1; overflow: auto; } .inner { height: 1000px; } 
 <div class="content"> <div class="left"> <div class="inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi asperiores deleniti culpa voluptatem in esse magnam sequi laborum quas ipsum vel, dolores natus ad reprehenderit enim nihil tenetur eaque, modi.</div> </div> <div class="right"> <div class="inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex repellat architecto ducimus hic. Ratione eius eos, atque, officia nemo quasi beatae voluptatem necessitatibus hic nam aliquid iusto quis laudantium reiciendis!</div> </div> </div> 

You can use NiceScroll ( jQuery Plugin ) for your page. 您可以在页面上使用NiceScroll( jQuery Plugin )。 You can apply it to a DIV object you want. 您可以将其应用于所需的DIV对象。

在此处输入图片说明

Live demo and sample code. 现场演示和示例代码。

Download open source code 下载开源代码

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

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