tags:

views:

29

answers:

3

Hi, i have a container div which is position:relative and the squares are position:absolute because i want to play with their positions.

alt text

Like what you see, the container does not fit the content except if the squares are positioned in Relative, is there a solution for this?

I don't want to just set the height for container because the squares are not static so i want something that resizes automatically.

Thanks

A: 

Hi Tom,

I need a bit more clarity in your question and depiction but I think I catch what you are saying.

I am guessing what is in the image above is what is currently happening but you want the gray, relatively positioned container to "surround" the abolutely positioned containers, wherever they may be?

If so, I would add just one more DIV after all your absolutely positioned containers that has clear:both attributed to it. That's my personal little tip for making sure the parent container hugs all of its kids, no matter where they go running off to.

Hope that helps

rob - not a robber
no rob, it is not possible to contain absolute positioned elements.. Your trick will work for floated elements though ;)
Gaby
i agree with you @Gaby
David
But what's the solution?
David
yup, it doesn't work.
hallie
+2  A: 

Unfortunately it is not possible to contain absolute positioned elements.. They are taken completely out of the normal flow, so nothing knows how to wrap around them..

Gaby
Thanks for answer, is it possible by changing DIV to <li> tags ?
David
@Tom, Nope :( the CSS rules apply to all elements in the same way.. You could use jQuery (a javascript framework) or plain javascript if you prefer and resize the container to fit the lowest div
Gaby
@Gaby et al, yeah, my fault. Too much wine at dinner. As mentioned, the absolute elements do not respect other containers on the X or Y index. Restructuring might not be necessary, but positioning method certainly. I assume you'd be writinng CSS with DOM control through JS, so why not dynamically write X and Y coordinates from the child, relative to the parent container?
rob - not a robber
A: 

If you know the height of the absolutely positioned elements, however, you can set the 'containing' div to a min-height of their top offset plus that known height. Again, it won't contain it in the proper sense, but it will be at least that tall.

D_N