I have two columns in my HTML page.
<div id="content"> <div id="left"></div> <div id="right"></div> </div>
Each of them occupies half of the page
#left { float: left; width: 50%; } #right { float: left; width: 50%; }
Is it possible to make it so that they flow independently? I mean, I want to be able to scroll down the left column, but remain at the top of the right column, instead of having to scroll down both columns at the same time.
To freeze the row/column we can use a simple HTML table and CSS. HTML: In HTML we can define the header row by <th> tag or we can use <td> tag also. Below example is using the <th> tag. We also put the table in DIV element to see the horizontal and vertical scrollbar by setting the overflow property of the DIV element.
The first one is with javascript: set the scrollTop property of the scrollable element (e.g. document. body. scrollTop = 1000; ). The second is setting the link to point to a specific id in the page e.g.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
See this fiddle
#content, html, body { height: 98%; } #left { float: left; width: 50%; background: red; height: 100%; overflow: scroll; } #right { float: left; width: 50%; background: blue; height: 100%; overflow: scroll; }
The earlier postings improved a little:
Fiddle: 2 independently scrolling divs
html, body { height: 100%; overflow: hidden; margin: 0; } #content { height: 100%; } #left { float: left; width: 30%; background: red; height: 100%; overflow: auto; box-sizing: border-box; padding: 0.5em; } #right { float: left; width: 70%; background: blue; height: 100%; overflow: auto; box-sizing: border-box; padding: 0.5em; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With