Forums | MacLife
You are not logged in.
#1 2006-10-05 4:14 pm
Scrolling Div
So, I'd like to have a div that will expand to the bottom of the page, and then scroll (as opposed to the whole page scrolling). Any ideas how to do this, since I can't give it a fixed pixel height or max-height?
Thanks!
_Nik
Offline
#3 2006-10-05 6:25 pm
- I'm with stupid
- Hey Crabman!

- From: Bakersfield, Ca
- Registered: 2005-02-01
- Posts: 192
Re: Scrolling Div
I'm with Miles.
But if you really want to, the only thing I know is to assign a height to the div, then give it a overflow:auto rule in the stylesheet. But then you'd either have to live with the fixed height or use Javascript to calculate the page size, and...
... really, I'm with Miles on this one.
This isn't who it would be if it wasn't who it is.
Offline
#5 2006-10-07 4:34 am
- cosmicosmo
- Chancellor Mmmm

- From: Peninsula, Ohio, US of A
- Registered: 2003-02-06
- Posts: 237
- Website
Re: Scrolling Div
If you position the div fixed or abosolutely; use right, left, and top to define the size of the div; and give it a bottom of 0, with overflow auto, it will have a scrollbar just for the div. Top can be in percentages. The div will always go to the bottom though, if you need the expansion. For expansion, create a div within that div that has the background styling and all the content. example
I hate your wimper
Offline
#6 2006-10-07 8:36 pm
- registered_user
- bulletproof
- From: padding: zero-pixels;
- Registered: 2000-12-19
- Posts: 16026
- Website
Re: Scrolling Div
here's an example of what I think you're trying to do:
http://www.casefoundation.org/about/news
and I must say, I absolutely hate using that site. It's not as bad with a scroll wheel, but without one, it's tragic enough that I leave quickly.
Offline
#7 2006-10-08 12:16 am
- Light Speed
- Doubter of Einstein

- Registered: 2002-08-17
- Posts: 3694
Re: Scrolling Div
registered_user wrote:
here's an example of what I think you're trying to do:
http://www.casefoundation.org/about/news
and I must say, I absolutely hate using that site. It's not as bad with a scroll wheel, but without one, it's tragic enough that I leave quickly.
That's a fixed height div and he wants an expanding one.
Offline
#8 2006-10-08 4:05 pm
- registered_user
- bulletproof
- From: padding: zero-pixels;
- Registered: 2000-12-19
- Posts: 16026
- Website
Re: Scrolling Div
oh, right. then nevermind. the usability issues dissolve away.
Offline
#9 2006-10-08 5:09 pm
Re: Scrolling Div
Thanks for the responses. I've uploaded what I have so far to give you a better idea of what I'm trying to do, and why I want a scrolling div as opposed to a scrolling page. Link.
Thanks again!
_Nik
Offline
#10 2006-10-08 5:18 pm
Re: Scrolling Div
cosmicosmo wrote:
If you position the div fixed or abosolutely; use right, left, and top to define the size of the div; and give it a bottom of 0, with overflow auto, it will have a scrollbar just for the div. Top can be in percentages. The div will always go to the bottom though, if you need the expansion. For expansion, create a div within that div that has the background styling and all the content. example
The problem I have then is that margin-left: auto margin-right:auto no longer works for centering my div...
_Nik
Offline
#11 2006-10-08 5:23 pm
- Light Speed
- Doubter of Einstein

- Registered: 2002-08-17
- Posts: 3694
Re: Scrolling Div
Not sure how to do what you need (I am on a deadline) but have you looked here to see if there is a solution?
http://glish.com/css/#techniques
Offline
#12 2006-10-08 11:43 pm
- cosmicosmo
- Chancellor Mmmm

- From: Peninsula, Ohio, US of A
- Registered: 2003-02-06
- Posts: 237
- Website
Re: Scrolling Div
GreenAlge wrote:
The problem I have then is that margin-left: auto margin-right:auto no longer works for centering my div...
It will be centered if you use the same left and right numbers, ie 'left: 10%; right: 10%). This won't allow the div to be fixed width, though, as it is in the example.
What do you want changed with your example? The example has the annoying requirement to scroll with two scroll bars to read the whole thing, unless you are on a rather giant monitor. You could perhaps modify it to something like this (with your images of course) to give a similar appearance but not require scrolling both the whole page and the content.
I hate your wimper
Offline
#13 2006-10-09 5:58 pm
Re: Scrolling Div
I'm with stupid wrote:
I'm with Miles.
Tell me someone else is laughing. Please. 
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#16 2006-10-10 9:07 pm
Re: Scrolling Div
Epic. I shall now go on a posting spree to get my postcount over 3k.
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#17 2006-10-12 5:05 pm
- I'm with stupid
- Hey Crabman!

- From: Bakersfield, Ca
- Registered: 2005-02-01
- Posts: 192
Re: Scrolling Div
Basseq wrote:
I'm with stupid wrote:
I'm with Miles.
Tell me someone else is laughing. Please.

oh now I get it!!! 
This isn't who it would be if it wasn't who it is.
Offline
#18 2006-10-13 5:40 pm
Re: Scrolling Div
I'm with stupid wrote:
Basseq wrote:
I'm with stupid wrote:
I'm with Miles.
Tell me someone else is laughing. Please.
oh now I get it!!!
Use your power wisely. :jedi:
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#19 2006-10-29 3:03 pm
- chuckaeronut
- MobileMe Web Gallery, dude!

- From: Unknown.
- Registered: 2003-03-25
- Posts: 184
- Website
Re: Scrolling Div
Here's what I'd do. I've done this tons in the past and it works beautifully. It's workaroundish, but currently CSS has no way of doing this except by height:100%;, which really doesn't let you say "I want this div to be 100 pixels shorter than the window all the time."
<div id=theDiv style="position:absolute; left:-5000px; top:100px; width:500px; height:0px; overflow:auto;">
lots of stuff here!
</div>
Up in the header, put...
<script>
function bodyWasResized() {
var it = document.getElementById("theDiv");
it.style.height = (windowHeight() - 100) + "px";
var divWidth = parseInt(it.style.width);
it.style.left = ( (windowWidth()-divWidth)/2 ) + "px";
//this code will run every time the user resizes the window.
}
function bodyJustFinishedLoading() {
bodyWasResized();
//this code will run when the page loads; put whatever you want here!
}
//don't worry about these; they're just functions that reliably return
//the width and height of the window in all possible ways to account
//for all the different ways modern browsers implement JavaScript.
//You can pretty much ignore these, but for the above code to work...
//they have to be there.
function windowWidth() {
return f_filterResults (
window.innerWidth ? window.innerWidth : 0,
document.documentElement ? document.documentElement.clientWidth : 0,
document.body ? document.body.clientWidth : 0
);
}
function windowHeight() {
return f_filterResults (
window.innerHeight ? window.innerHeight : 0,
document.documentElement ? document.documentElement.clientHeight : 0,
document.body ? document.body.clientHeight : 0
);
}
function f_filterResults(n_win, n_docel, n_body) {
var n_result = n_win ? n_win : 0;
if (n_docel && (!n_result || (n_result > n_docel)))
n_result = n_docel;
return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
</script>
In the body tag, put...
onload="bodyJustFinishedLoading();" onresize="bodyWasResized();" along with whatever other attributes you may or may not have.
Last edited by chuckaeronut (2006-10-29 3:05 pm)
Offline
#20 2006-10-29 3:26 pm
- chuckaeronut
- MobileMe Web Gallery, dude!

- From: Unknown.
- Registered: 2003-03-25
- Posts: 184
- Website
Re: Scrolling Div
I made a little example page that's a LITTLE more complicated (just to get a cool transparent background without making the text itself transparent), but the effect is the same.
Here it is!
Offline
#21 2007-05-18 3:26 am
- cosmicosmo
- Chancellor Mmmm

- From: Peninsula, Ohio, US of A
- Registered: 2003-02-06
- Posts: 237
- Website
Re: Scrolling Div
You can have a fixed space above the div with just CSS. This example is like yours (chuckaeronut), but with CSS, and no fixed-width content area. I'm not shure how to fix the width and still make it work.
I hate your wimper
Offline
#22 2007-06-02 4:44 pm
- chuckaeronut
- MobileMe Web Gallery, dude!

- From: Unknown.
- Registered: 2003-03-25
- Posts: 184
- Website
Re: Scrolling Div
Yeah, you can give a div left: top: right: and bottom: attributes with position: absolute; and the browser will calculate the size of the div and all that, but, IE doesn't jive with it. 7 might, but I'd be surprised. I know 6 doesn't. Sad state of standards compliance, indeed. 
Offline
#23 2007-06-05 3:57 pm
- penguinsocks
- thirteen cent pinball
- From: Vancouver, BC
- Registered: 2005-08-04
- Posts: 78
- Website
Re: Scrolling Div
By the looks of it, you really don't need an expanding div. Secondly, a column that wide, if you're planning to fill it with text from left to right, is going to be very onerous for your users unless you're using 26 pt type. Add to that the exhaustion of secondary scrolling for a div that tall...
so much for having the fastest MBP available.
Offline

