tags:

views:

350

answers:

2

Hi all ... I have these two divs one inside another and I have the styles defined .. encapsulating one is relative and the child is absolute .. Now isn't the child supposed to be positioned according to the left top corner of the outer div, #RightSection? .. but its doing it according to the browser window ... any leads? thx in advance

        <div id="RightSection">
            <div id="Panels">

            </div>
        </div>

#RightSection
 {
     position: relative;
 }

#Panels
 {
    position: absolute;
    background-color: Blue;
    width: 100px;
    height: 100px;
    z-index: 9000;
 }
+1  A: 

Absolute positioning inside of relative positioned elements is supposed to do what you describe, but it's not always supported behaviour. What browser are you use and what DTD are you serving?

See http://www.brainjar.com/css/positioning/default4.asp for details. It also has a demo of the positioning so that you can verify it works or not in your browser.

I can confirm that this does not work in IE6. I can't vouch for other browsers while I'm at work, though. Brief searching online leads me to believe that this problem exists in IE7 too, and would conceivably be an issue in IE8 as long as it's rendering in IE7 mode.

Welbog
Relative means positioned relative to it's normal rendered position. Absolute means it is positioned relative to its containing block. http://www.w3schools.com/css/pr_class_position.asp
tj111
+1  A: 

I have also found that if I do not declare the top and left css parameters for absolutely positioned elements it seems to ignore a parent above it and just jump to the body of the page.

Try just giving it top and left parameters, see if it helps,

#Panels
 {
    position: absolute;
    top: 0;
    left: 0;
    background-color: Blue;
    width: 100px;
    height: 100px;
    z-index: 9000;
 }

It should look just fine once you add in those default parameters.

Sir David of Lee
Also, without defining the top and left parameters, after testing a minute ago it seems the absolutely positioned object goes where it would if it were statically positioned- except on its own layer above everything else, so adding a static div below it would just make the two overlap.So you need the top and left parameters to tell it where to go, otherwise it acts like its a simple static area.As a test try giving your #RightSection div a height our a bunch of padding, without parameters on the inner div it should show up under that #RightSection div
Sir David of Lee
*not under but inside the outer div. So giving the outer div 50px of padding will make the inner on show up 50px down on the page
Sir David of Lee