Sorry for the confusing title. I have a parent div with an absolutely-positioned div inside.

Is it possible, for the parent-div to stretch to contain the child div?

I know that absolutely positioning an element removes it from the page flow, but still, maybe there's a trick i don't know?

4 answers

3
points

Unfortunately not in the way that it sounds you are proposing. Absolutely positioned elements will not affect the container of a parent element. There maybe another way to achieve the result you are looking for (with or without absolute positioning) but without knowing what you are trying to achieve makes it hard to give you the right answer.

Answered over 7 years ago by Efficient Pixel
Tilman 1
0
points

Thanks for your answer. Ok, I feared as much.

Will just float the child-div then.

I was trying to do the whole "2 Column Layout" without floats. Serves me right, haha.

Answered over 7 years ago by Tilman
  • That's what I figured you were doing. Efficient Pixel over 7 years ago
  • I'm curious. Why do it without floats? Ben Shoults over 7 years ago
-1
points

I may be understanding your question wrong. If you set your parent element to position: relative; then the child element will be positioned absolutely in relation to the parent element. This may or may not still remove it from the page flow.

Answered over 7 years ago by Ben Shoults
Jakob 17
-2
points

javascript is a solution for this. since you can calculate the position of a box based on the left upper corner of the box and than read via the style settings where current position lies (via DOM) you could stretch the box. btw. if you want to contain something never set it absolute it knocks the sense out of the meaning absolute "a relative absolute position" ? anyhow JS could recalculate this and to make it browser compatible jQuery in this case

Answered over 7 years ago by Jakob