views:

327

answers:

3

I approximatley this structure

<div> <div id='1'> </div> <div id='2'> </div> </div>

I want to make it so that when div 1's content becomes too large for it and div 2 to fit in the main div, it will get a scrollbar and not push anything off the bottom of the parent div.

How can I do this in CSS?

EDIT:

the parent div (or rather, its parent) has a set height. and at this point setting overflow : scroll on div1 just causes it to go beyond the bottom with a scrollbar on the side.

A: 

Use

overflow:scroll

in your CSS on div1.

Peter
Sorry for the confusion. I tried this and it is not working. Somehow div 1 is not inheriting a max height from the parent
AlexH
See neutrino's comment. YOu may also have to set a fixed height for div 1.
Peter
A: 

You can use the overflow setting:

#id
{

   overflow: scroll;

}
okoman
+1  A: 

First, you need overflow: scroll on div 1. And also you need to somehow fix such a value of its height that the div will need a scrollbar after reaching this value. Should be no problem if you have a fixed height or max-height on your parent div.

EDIT

Check this out: http://www.quirksmode.org/css/overflow.html. It seems (unfortunately) that you nevertheless need a value for your div 1's height. I figured out max-height will do, too. And, by the way, for the scrollbars to appear only when necessary, you need overflow: auto.

neutrino
ok, but the contents of div 2 can be of varying height. how do I deal with this?
AlexH
See my edit above
neutrino