I have an absolute position child div that i'm trying to fit in a div of a template. How can I get the parent div to expand to the content of the absolute pos div???
Right now, the parent div appears empty while the child div overlays it.
Code:
<div style='border:solid 2px #0000FF;'><!-- parent that's not growing-->
<div style='position:relative;border: solid 1px #00FF00;'> <!-- child that's not growing -->
<div style='width:100%;position:absolute;top:0px;left:0px;border:solid 1px
#ff0000;'>text<BR><BR>text</div> <!-- problem, but must be absolute-->
</div>
</div>
I don't think you can: when you absolutely position an element, by definition you take it out of the document flow, so as far as positioning goes that element is no longer a "child" (though it still is semantically). Is there a reason you cannot absolutely position the parent element, instead? (Or for that matter, is absolute positioning really required?)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Sorry for wrong info there - I was thinking the child was floated. A clearing div will only work for a float - with absolute positioning you will have to set the parent height.
It doesn't appear you need to absolutely position that div since you are giving it top:0 and left:0 and the div it's directly inside is position:relative. What happens if you just drop the position:absolute? I'm probably missing something obvious, but it appears about the only thing position:absolute is doing for you here is causing the problem you are trying to solve...
Bookmarks