views:

523

answers:

2

hi,

im building a website that has a layout similar to http://maps.google.com: a header, a sidebar on the left and a map on the right.

on the google maps website when the content of the sidebar exceeds the height of the screen a vertical scrollbar appears next to it (e.g. if you type 'restaurant' in the search box). Im trying to achieve a similar effect and have tried various options but nothing seems to work the right way. setting the height of the sidebar to auto or 100% does not work since the sidebar does not start at the top of the page - the vertical scrollbar is either too short and does not reach the bottom of the page (auto case) or too long and exceeds the height of the page (100% height case). i think google uses js to calculate the height of the sidebar.

any ideas on how i can get this to work?

thanks, yulka

+1  A: 

You can make the left hand column a div with css that contains this:

overflow: scroll

If there is any overflow, a scrollbar will appear and that div will be scrollable. You'll need to wrap all content in a fixed-width div so that you don't get horizontal scrollbars as well.

Edit: An Example.

<html>
  <head>
    <style type="text/css">
      #example{
        overflow: scroll;
        height: 200px;
        width: 100px;
        border: 1px solid red;
        color: #FFF;
        background-color: #000;
      }
    </style>
  </head>
  <body>
    <div id="example">Hello, World!</div>
  </body>
</html>

Now, if you replace "Hello, World!" with:

Line One<br />
Line Two<br />
Line Three<br />
Line Four<br />
Line Five<br />
Line Six<br />
Line Seven<br />
Line Eight<br />
Line Nine<br />
Line Ten<br />

You should get the scrolling action as soon as the text is too long to fill the div.

Mike Trpcic
If this is the answer, I hate you. I thought it up an hour ago and swore it had to be more complicated than this.
Chacha102
(Just to be clear, I kidding about the hatred part)
Chacha102
in my case the problem is the column height is not known.
yulka
yulka: Just set the div height to 100%. It will then take up 100% of the available space, and scrolling will occur after that.
Mike Trpcic
A: 

I ended up using ui.layout jquery plugin, it works perfectly for me: http://layout.jquery-dev.net/index.html

yulka