SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict vflytrap's Avatar
    Join Date
    Aug 2003
    Location
    Twighlight Zone
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Absolute Positioning relative to the Div

    When I used pixel based absolute positioning, and I use it within a layout div, is there a way to make the x/y distance relative to the div that the element (with absolute positioning) is being built within?
    My point would be building a site that "looks" fluid (can recenter, etc.), but isn't (internal content doesn't shift).


    ahhh, I'm such a pixel freak.

    S*
    _________________________________________
    Rockin' in the free world...
    brilliant nonsensical ramblings

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,354
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    I think I half answered this in your other thread

    To make a parent element contain a psoitioned element the parent element needs to have a property set for position other than static.

    What this usually means is that you give your parent element a position:relative but don't give it any co-ordinates. As you have not supplied any co-ordinates then the flow of the document is not altered in any way and the page behaves exactly as before.

    You can now position your inner element and the starting point will be the top left of the parent element.

    Basically a parent element is defined as the nearest ancestor that has a property set for position (other than the default of static).
    Code:
    .outer {
    position:relative;
    width:500px;
    height:300px;
    margin:auto;
    }
    .inner{
    position:absolute;
    top:100px;
    left:100px;
    width:150px;
    height:50px;
    }
     
    html
    <div class="outer">
    <div class="inner">Absolutely Placed</div>
    </div>
    Hope that all makes sense.

    Paul

  3. #3
    SitePoint Addict vflytrap's Avatar
    Join Date
    Aug 2003
    Location
    Twighlight Zone
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Paul O'B
    Hi,

    I think I half answered this in your other thread
    That you did - ha - you got to this before me!
    Thank you so much - you answered my question perfectly. Quite helpful in fact. Are you available as a 24/7 CSS consult?

    S*
    _________________________________________
    Rockin' in the free world...
    brilliant nonsensical ramblings


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
  •