Absolute positioning and variable height content

aka Rohan's picture

He has: 200 posts

Joined: Feb 2006

Am I right in assuming that you cannot use aboslute positioning for a container where the height varies with the amount of text in it?

For example in this site the 'News' section expands as more posts are added which pushes the footer down.

Now if I was to use absolute positioning instead of floats could I still achieve the same effect?

I've been playing around with positioning and can't seem to get this to work. I've managed to get general absolute positioning to work here but could only achieve that by applying relative positioning to the containing #main div and a fixed height. If I used no positioning for #main, then the boxes aligned with the browser not #main and if I used absolute positioning for #main then the footer shifts up under the header.

What I really need is for the footer to adjust with the main content so that it always remains below.

I'm guessing though that because the absolute positioning takes the boxes aout of the normal flow of the page that this is probably not possible.

I tried using a with p.clear {clear: both;} like I use with my floated divs to prevent overlapping of elements below but this doesn't work in this case.

Cheers in advance guys Smiling

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

monkeyboy wrote: Am I right in assuming that you cannot use aboslute positioning for a container where the height varies with the amount of text in it?

At first I thought: 'Don't be silly, of course it can!' Then I realised you meant that the parent of a box containing text should scale according to how much text there is in the child box. That is not possible when position: absolute; Sad

You will have to use floats in this case. My suggestion is to get hold of the Firebug extension for Firefox (it's a good enough add-on for me to use Firefox occassionally!) and study how http://www.apaddedcell.com works (the useful style sheet is at: http://www.apaddedcell.com/themes/apaddedcell/style.css ). It has a sidebar floating to the right and a footer with clear: both; set. Smiling

monkeyboy wrote: I've managed to get general absolute positioning to work here but could only achieve that by applying relative positioning to the containing #main div and a fixed height. If I used no positioning for #main, then the boxes aligned with the browser not #main and if I used absolute positioning for #main then the footer shifts up under the header.

That's correct behaviour; you'll find it useful later on. Smiling

a Padded Cell our articles site!

aka Rohan's picture

He has: 200 posts

Joined: Feb 2006

That's awesome, thanks Jeeves. I didn't realise you could add the clear:both to the footer and it would still work either. Now I can go and dump those 's I've been using everywhere Laughing out loud

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.