Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Independent column scroll in HTML page

Tags:

html

css

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.

like image 330
Mika H. Avatar asked Mar 16 '13 19:03

Mika H.


People also ask

How do you fix a column when scrolling in HTML?

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.

How do I create an auto scroll in HTML?

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.

How do you vertically scroll in HTML?

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.


2 Answers

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; } 
like image 177
dezman Avatar answered Sep 21 '22 19:09

dezman


The earlier postings improved a little:

  • 100% html and body size .... without scroll bar
  • margins for the left and right boxes
  • individual scrollbars only when needed ("auto")
  • some other details: Try it!

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; } 
like image 25
odungern Avatar answered Sep 20 '22 19:09

odungern