Results 1 to 6 of 6

Thread: Positioning problem.

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Positioning problem.

    Hello all,
    I was trying to position a div vertically and horizontally in the center(in all resolutions) but unfortunately due to some reason the div gets far too much to the right even when I place the left positioning 50%.

    My code so far is something like this:

    Code:
    <div id="test" style="position:absolute;left:50%;top:50%;height:300px;width:500px;border:1px solid;"></div>
    Are there any hacks or tips for this problem?? Any help would be greatly appreciated. Thanks in advance.

  2. #2
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    do not position horizontally:, use margin-left: auto; margin-right: auto,
    the 50% says it should be PLACED starting from 50%, not centered.

  3. #3
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    also, parent ought to have text-align: center.

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I meant centering vertically as well as horizontally.

  5. #5
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The example I provided is for horizontal centering- for vertical centering there are several methods, and probably none will work for document body as it won't have height defined- I guess you just need to stick with 50% for vertical (top).

  6. #6
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok thanks for your help anyways.

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
  •