Results 1 to 8 of 8

Thread: Centering page in any browser

  1. #1
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Centering page in any browser

    Hello there! I am having this problem of centering my page. It is because I want my page to be viewed in center using any screen resolution and/or browser. I am currently using FF3 with screen resolutions of 1024x768. So, I tried using
    Code:
    <center></center>
    but it didn't work in mozilla but on the other browsers it did. I would like to avoid using the CSS
    Code:
    left: 300px; top: 0px;
    or any margins. My divs remain on the left side if I am not going to use the
    Code:
    left: 300px; margin-left: 2em;
    and so on.

    I saw a some pages that are centered even if using different browsers and screen resolutions. How do I resolve this?

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Why would you not want to use CSS? Could solve this in about 4 lines if you did.

    Link to the page so we can see the creation you have to help in a non-CSS (and apparently non-Standards) way?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by BLiZZaRD View Post
    Why would you not want to use CSS?
    I tried using CSS but, in other browsers and screen resolutions, my page looks cluttered. I hope you get what I mean.

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Then you are coding correctly Link?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Whenusing CSS (which IS truly simple and cross-browser supported) you would make a container div, then in the body styling of the CSS you would text-align: center;

    the HTML layout would look similar to:

    HTML Code:
    <body>
    <div class="container">
    //rest of content here
    </div>
    </body>
    </html>
    In the CSS, you would set width specs for .container like so:

    Code:
    .container {
          width: 80%;
    /* any other special attributes needed */
    }
    Using % instead of an em or px will make it that percentage of the viewport, so no matter the resolution it would only take up 80% of it, and with the body text-align centered, it would center that 80% in the full width of the viewport.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    The other way around to center an element is by using the centering technique for block elements (highlighted):
    Code:
    <style type="text/css">
    #wrap{
    width:500px;
    margin:20px auto;
    border:1px solid red;
    text-align:center;
    }
    </style>
    <div id="wrap">This is the content of wrap div</div>
    ...this should work well on FF, but IE, being on quirksmode, must have a DTD:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    ...so the complete code which works cross-browser and will center your element on any resolution is:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <style type="text/css">
    #wrap{width:500px;margin:20px auto;border:1px solid red;text-align:center;}
    </style>
    </head>
    <body>
    <div id="wrap">This is the content of wrap div</div>
    </body>
    </html>
    Also note the center is a deprecated tag, and should'nt be advocated.

    Hope that makes sense.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Methinks the redundant button is stuck... heh.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by BLiZZaRD View Post
    Methinks the redundant button is stuck... heh.
    Not redundant...just thorough!

    Rananga, rightfully, pointed out that a simple text-align:center will not achieve centered content in all browsers.

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
  •