Results 1 to 3 of 3

Thread: CSS Position Center

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Resolved CSS Position Center

    How would I position a div so that its horizontical(left-right) center would be the center of the page(the center of body)? Can I somehow set it's handle to it's own center and just use: left:50%; ?
    Last edited by vbNeo; Oct 9th, 2004 at 06:25 AM.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There are two ways, and you need a fixed width for both. For in-flow boxes, you use margins.
    Code:
    #thediv {
      width: 100px;
      margin-left: auto;
      margin-right: auto;
    }
    For out-of-flow boxes, you use, uh, margins
    Code:
    #thediv {
      position: absolute;
      width: 100px;
      margin-left: -50px; /* Half the negative width. */
      left: 50%;
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Ah, nice - thanks!
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

Posting Permissions

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



Click Here to Expand Forum to Full Width