SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    center all content

    What's the best way so simply center everything on the page?

    I have an element I would like to be in the center of the page (vertically) no matter the width of the window.

    how should I go about this?

    use the <div align="center"> tag? or is there a CSS way?

    Rich

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

    Do you mean something like this:

    http://www.wpdfd.com/editorial/thebox/deadcentre3.html

    Or do you just mean horizontally, in which case you can use margin-right:auto and margin:left:auto on a fixed with element . (You will also need to use text-align:center in the parent element for ie5, 5.5.).

    Paul

  3. #3
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    center content

    Yes pretty much. I just need to have it centered like it was center justified, not the top and bottom.

    Rich

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

    To center a page horizontally that is 755px wide you can use this.
    Code:
    body {
    text-align: center;
    margin: 0px;
    padding: 0px;
    }
    .central {
    margin-right: auto;
    margin-left: auto;
    position: relative;
    width: 755px;
    text-align: left;
    }
    And then after the body tag :
    Code:
    <div class="central"> 
    all the rest of your page.....
    </div>
    (To centre vertically as well just look at the source code from the first link I gave you above.)

    Hope that helps.

    Paul


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
  •