PDA

View Full Version : Absolute DIV in Relative DIV


Jerome
03-22-2003, 11:32 AM
Hmm...

When You make a document layout using absolute DIVs f.e.

MyDIV
top:100px;
left:100px;
width:200px;
height:200px;

The MyDIV will be always at the same position in relation to the document.

My question is:

Is it possible to position an absolute MyDIV not absolute in relation to the document, but absolute in relation with another FloatingDIV?

So that when I move the FloatingDIV from left to right the absolute MyDIV within it stays at the same position in relation to this FloatingDIV

Thanks for Your effort,
Jerome

brothercake
03-22-2003, 07:13 PM
Indeed it is ...

<div style="position:relative;left:10px;top:10px;padding:20px;width:200px;height:200px;background-color:pink">


<div style="position:absolute;left:0px;top:0px;padding:20px;width:150px;height:150px;background-color:yellow">


<a href="#">All your base are belongs to us</a>


</div>



</div>

Spookster
03-22-2003, 07:20 PM
I am starting to get into CSS layouts now verses all table layouts. Now how exactly does one use this concept of absolute divs inside of relative div to create layouts that adjust to browser size similar to what happens with using percentages with tables?

Jerome
03-22-2003, 08:25 PM
First of all thanks brothercake!

Secondly, Spookster, I don't no if it helps You but my site-layout is made up with absolute positioned DIVs which are percentage of the screen (document). This way the layout adjusts to the screenwidth.

MyDIV
top:5%;
left:5%;
height:45%;
width:25%

a perfect DIV for let we say navigation!

Jerome

brothercake
03-22-2003, 08:50 PM
Indeed - percentages are a good way of defining column widths that are flexible.

Check out the many links in this previous thread - http://www.codingforums.com/showthread.php?s=&threadid=13083

Not to mention my current raison d'etre (http://af.brothercake.com/_template.php) :D

cg9com
03-22-2003, 09:37 PM
absolute divs with percentage based layout? sounds like a disaster.
unless you have very little content, i say reserve the absolute for something on an exact pixel to pixel basis.

brothercake
03-22-2003, 11:08 PM
why? I mean I've never needed to do it, but in principle:

div.className{
position:absolute;
left:10%;
top:15%;
}

would be fine; no probs.

cg9com
03-23-2003, 08:29 AM
after testing my ideas, its not too bad. ill retract that statement. :D