Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts

    Question Centering my content

    Hi

    I am developing a page best fit for 1024x768 screen resolutions, but I want 800x600 screens to work with it too. Therefore, I have the content only 760px wide, so that on an 800x600 screen, it fills the entire browser window, but on 1024x768, there is gray space around the edges. I want to center the table that holds all my content, but I don't want to use absolute positioning, because I want the page always to be centered, even if the window isn't maximized all the way. The reason I don't just use align=center in the table tag, is that I want the page to be XHTML Strict, which doesnt allow the align attribute.

    Dan Barr

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    You using css? I would use a div and give it the css of, margin : auto auto; to center it and, either give the div a fixed width or use padding, to vary the whitespace either side.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    Regular Coder Graft-Creative's Avatar
    Join Date
    Aug 2004
    Location
    Web Designer - North East Lancashire U.K.
    Posts
    842
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by whizard
    Hi

    I am developing a page best fit for 1024x768 screen resolutions, but I want 800x600 screens to work with it too. Therefore, I have the content only 760px wide, so that on an 800x600 screen, it fills the entire browser window, but on 1024x768, there is gray space around the edges. I want to center the table that holds all my content, but I don't want to use absolute positioning, because I want the page always to be centered, even if the window isn't maximized all the way. The reason I don't just use align=center in the table tag, is that I want the page to be XHTML Strict, which doesnt allow the align attribute.

    Dan Barr
    Yep, like Bazz said, wrap your table in a <div> like this
    css:
    Code:
    div#container {
    	width: 760px;
    	margin: 0 auto;
    }
    You'll also need to add this to your body tag in css:
    Code:
    body {
    	text-align: center;
    }
    Well that's how I do it anyway.

    Gary

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts

    Smile Thank You

    Thx so muuch!

    Dan


  •  

    Posting Permissions

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