Results 1 to 7 of 7

Thread: Code for centering

  1. #1
    Join Date
    Feb 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code for centering

    any one no the html code that centers my website in any browser safri,ff,ie , ex....

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    <div align="center">
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The code listed above will centre only the div it styles. This code will centre the entire site. Be sure to "uncentre" those things you want left justified.
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    	<title>An XHTML 1.0 Strict standard template</title>
    	<meta http-equiv="content-type" 
    		content="text/html;charset=utf-8" />
    	<meta http-equiv="Content-Style-Type" content="text/css" />
    <style type="text/css">
    body { margin: 0 auto; /* for modern browsers */
          text-align:center;  /* for older browsers */
          }
          </style>
    
    </head>
    <body>
    
    <div>... site code here
    
         <p>... Your HTML content here ...</p>
      <p>
        <a href="http://validator.w3.org/">validate the xhtml</a>
      </p></div>
      
    </body>
    </html>
    Last edited by jlhaslip; 02-18-2007 at 06:49 AM. Reason: fix stuff

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    IE supports XHTML really badly.

    http://www.hixie.ch/advocacy/xhtml
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Styling the body like so:

    Code:
    <style type="text/css">
    body { margin: 0 auto; /* for modern browsers */
          text-align:center;  /* for older browsers */
          }
          </style>
    Can lead to more problems in a complex layout than will using a wrapper division:

    Code:
    <style type="text/css">
    #wrapper { margin: 0 auto; /* for modern browsers */
          text-align:center;  /* for older browsers */
          }
          </style>
    HTML Code:
    <body><div id="wrapper">
    
    Your markup here
    
    </div></body>
    Also, text-align:center can have unexpected consequences, especially if absolute positioning is used within the content of an element so styled.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Is the align attribute depreciated for <p>?
    - Mike

  7. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by mburt View Post
    Is the align attribute depreciated for <p>?
    Yes it is. You can have a look at this page

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
  •