Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Absolute / Relative Position Not Working

  1. #1
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Absolute / Relative Position Not Working

    I am trying to position a div with absolute positioning, relative to a container div. It works when viewed in IE7, but not in Firefox 2. Firefox seems to ignore the parent or container div that has relative position set.

    The page is here:

    http://www.landscapeyard.com.au/index.html

    The div that I need positioned is the 'promoarea' div, and the container div is 'col4'

    CSS:

    Code:
    #col4 {
    	position:relative;
    	background-color:#0066FF;   /* only used for browser testing - remove when finished */
    	margin:10px 0 0 370px;
    }
    
    #promoarea {
    	position:absolute;
    	border:1px solid gray;
    	top:5px;
    	width:340px;
    	height:250px;
    }
    HTML:

    Code:
    <div id="col4">
        <div id="promoarea" style="background:url(images/promo_clad.jpg)">
            <div id="promoitem">
    	<p>Come into our yard to see our great range of cladding from only $59 / square metre!</p>
            </div>
        </div>
    </div>
    I have tried changing position to relative on the promoarea div, but I get the same result..

    I can fix the problem by removing position:relative from the container div, and setting the top position to 225px. But, I'd really like to know why Firefox is ignoring the container div's position setting.

    Can anyone see where I've gone wrong?

    Thanks in advance.

    Liam.
    Last edited by liam77; 08-01-2007 at 04:37 AM.

  2. #2
    Join Date
    Aug 2007
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    I tried the following and it bumped the promo image down (FF2)

    #promoarea {
    position:absolute;
    border:1px solid gray;
    top:50px;
    width:340px;
    height:250px;
    }

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Sometimes you need to specify both left and top to get an absolutely positioned element to respond as expected. Either value or both can be 0, if desired, but should still be specified.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I looked at this a bit more. The only differences between IE and other browsers are accounted for by:

    1 ) Different default margins/padding on the p element.

    2 ) Different default margins/padding on the body element.

    Try this:

    Code:
    <div id="col4">
        <div id="promoarea" style="background:url(images/promo_clad.jpg)">
            <div id="promoitem">
    	<div>Come into our yard to see our great range of cladding from only $59 / square metre!</div>
            </div>
        </div>
    </div>
    By changing all elements to div's, the differences become much less.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by studiocreek View Post
    I tried the following and it bumped the promo image down (FF2)

    #promoarea {
    position:absolute;
    border:1px solid gray;
    top:50px;
    width:340px;
    height:250px;
    }
    Thanks for the suggestion, but it still displays differently between IE and Firefox... What I'm really looking for is a way to get them both to display the same page layout.

    Liam.

  6. #6
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Try this:

    Code:
    <div id="col4">
        <div id="promoarea" style="background:url(images/promo_clad.jpg)">
            <div id="promoitem">
    	<div>Come into our yard to see our great range of cladding from only $59 / square metre!</div>
            </div>
        </div>
    </div>
    By changing all elements to div's, the differences become much less.
    Thanks for the suggestion, but it doesn't fix the problem unfortunately. I set the margins and padding to 0 by default in the css with the * tag.

    Code:
    * {
    	margin:0;
    	padding:0;
    }
    I'm still puzzled with why Firefox seems to be getting the positioning wrong. It is ignoring the positioning set for it's containing div.

    Is that how it looks to others as well? I know that Firefox is usually right, and IE wrong, but this seems to contradict it.

    Liam.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    * {
    	margin:0;
    	padding:0;
    }
    The above does nothing sometimes in some browsers. This demo looks nearly identical in FF, Opera, and IE:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #col4 {
    	position:relative;
    	background-color:#0066FF;   /* only used for browser testing - remove when finished */
    	margin:10px 0 0 370px;
    }
    
    #promoarea {
    	position:absolute;
    	border:1px solid gray;
    	top:0px;
    	width:340px;
    	height:250px;
    }
    </style>
    </head>
    <body>
    <div id="col4">
        <div id="promoarea" style="background:url(images/promo_clad.jpg)">
            <div id="promoitem">
    	<div>Come into our yard to see our great range of cladding from only $59 / square metre!</div>
            </div>
        </div>
    </div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    This demo looks nearly identical in FF, Opera, and IE:
    Hmm, thanks for that. It must be something to do with other parts of the CSS or html for my page then. I'll play around with it and see which part of the code is messing it up.

    Liam.

  9. #9
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The problem happens when I add in my left column (col3):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #col3 {
    	float:left;
    	width:350px;
    	margin:10px 0 0 0;
    	text-align:justify;
    }
    
    #col4 {
    	position:relative;
    	background-color:#0066FF;   /* only used for browser testing - remove when finished */
    	margin:10px 0 0 370px;
    }
    
    #promoarea {
    	position:absolute;
    	border:1px solid gray;
    	top:0px;
    	width:340px;
    	height:250px;
    }
    </style>
    </head>
    <body>
    <div id="col3">
            <p>Here at the Landscape Yard, you'll find all that you need to make your garden flourish.  Create an outstanding Alfresco area to suit our West Australian lifestyle with our unique products. </p>
    		<br />
            <p>Whether you are planning a stunning courtyard, planting a new garden bed, installing a <a href="water.html">water feature</a> or even creating a children's play area, we've got everything that you need to create a fantastic garden.</p>
    </div>
    <div id="col4">
    	  	<div id="promoarea" style="background:url(images/promo_clad.jpg)">
    			<div id="promoitem">
    				<p>Come into our yard to see our great range of cladding from only $59 / square metre!</p>
    			</div>
    		</div>
     </div>
    </body>
    </html>
    When that column is added in, Firefox displays col4 incorrectly. It shifts it up the page. I just can't work out why it does it.

    Liam.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I just copied your code from your post and viewed it in Opera, FF and IE 6 & 7. Aside from the fact that IE exhibits slightly different default margins for the <p> tag, they all looked about identical.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •