Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: have a div after an absolute positioned div

I was wondering how to do this, my current mark up is as follows:

<div id="playArea" style="position: relative;">
    <div id="widget1" class="widget" style="position: absolute; left: 295px; top: -1px; width: 313px; height: 269px;">Hello</div>
    <div id="widget2" class="widget" style="position: absolute; left: 63px; top: 35px; width: 80px; height: 42px;">World</div>
    <div style="position: absolute; left: 534px; top: 329px; width: 183px; height: 251px;">Bye</div>
</div>

Now, if I create a paragraph tag after the last </div>, the content of the p tag is not appearing under all of these div's in the browser. Any ideas how i can do this?

Thanks guys

like image 975
phpNutt Avatar asked Dec 23 '09 21:12

phpNutt


2 Answers

If you're using absolute positioning but you don't know the height of what you're positioning, that is a problem that HTML isn't very good at solving. I have seen (and probably written) hacks where JavaScript is used to position an element based on the offsetHeight of another.

But you might be better off using the CSS float property instead of absolute positioning. float and clear are pretty good for positioning things like you want, without sacrificing automatic page flow.

like image 84
easeout Avatar answered Sep 19 '22 02:09

easeout


You'll have to give the playArea a height value, absolute divs will not expand their parent

like image 40
Steve H Avatar answered Sep 17 '22 02:09

Steve H