tags:

views:

381

answers:

5

say I have something like

<body><div id="a"><div id="b">some content</div></div>more content<body>

and I don't know how much height "some content" is going to be. But I have #b styled to position: absolute and #a styled to position: relative so #b's position is relative the the top left corner of #a. Is there some way I can make #a expand to contain #b some that "more content" gets pushed after?

thanks

A: 

No. I think you need to describe your original task and people will help you.

nightcoder
A: 

that is a problem that is usually solved by including an element that has a "clear: both" style before the more content

<body><div id="a"><div id="b">some content</div></div><div style="clear:both;"></div>more content<body>

EDIT Actually, without a full context it's hard to give a full answer. You should also try including such a "clear: both;" element at the end of div#a like so:

<body><div id="a"><div id="b">some content</div><div style="clear:both;"></div></div><div style="clear:both;"></div>more content<body>
Miky Dinescu
+1  A: 

No. Absolute positioning removes elements from document flow. Their parent and sibling tags have no way of knowing that they are overlapping an absolutely positioned element or not.

greyfade
+1  A: 

It sounds like position relative for #b might be a better solution.

As #b is the first element in #a it woudl naturally appear in the top left corner of #a, so position relative will position relative to the same point as position absolute.

Also, say you want to push #b down by 30px, then you set

#b{position:relative;top:30px;margin-bottom:30px;}

Content will clear the bottom of #b because position:relative leaves a block in the content flow equal to the height of #b + 30px;

wheresrhys
+2  A: 

Your example is flawed as there is no actual need to have pos:abs on div#b as by default that element would be set at the top/left of div#a.

Using css position will take its applied element outside of the normal markup flow, even if you was to use pos:rel on div#b it would only increase the height of div#a it would not take into consideration any positioning you may have also applied to it.

There is a way you could achieve what you are after, but that would rely on using JavaScript.

Phunky