Results 1 to 5 of 5

Thread: Getting a Div to center

  1. #1
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Getting a Div to center

    I am using the following code to try and make a centered section. I cant work out what to use to make the div section in the middle of the page (vertially)

    Any suggestions?

    Code:
    <html>
    <head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html;">
    <style type="text/css">
    
    	
    	body {
    		background:#FFFF00;
    
    		}
    	
    	#main {
    		border:1px solid #000; 
    		background:#fff;
    		padding: 1px 1px 1px 1px;
    		}
    
    	h1 {
    		font-size:14px;
    		padding-top: 5px;
    		}
    	
    </style>
    
    </head>
    <body>
    
    <div id="main">
    
     Text here!
    </div>
    
    </body>
    </html>
    Last edited by kittenesque; 08-18-2006 at 10:24 AM.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    <style type="text/css">
    <!--
    body {
    	background:#FFFF00;
            margin: 0 auto;
            width: 80%;
            text-align: left;
    }
    //-->
    </style>
    Where width: 80% is equal to the width .... you can use % or px or em .... the margin property is what will center the whole page and text-align will ensure that all of your text is justified normally

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by pissa
    <!--
    "Hiding" script or style sheet content hasn't been necessary for many years.

    body {
    background:#FFFF00;
    Specifying either a foreground or background colour but not the other can lead to colour clashes. Not everyone will have the same default colours as the author. If you start specifying colours for one thing (foreground text, background colours or images, or link text), do the rest as well.

    Where width: 80% is equal to the width .... you can use % or px or em
    Though pixel lengths should often be avoided except in relation to images or other content of fixed size (which doesn't include text).

    Don't use pixels to define font sizes: only use percentages. The reasons can be found in the archives of these forums, as well as other places on the Web.

    ... text-align will ensure that all of your text is justified normally
    Why wouldn't it be? There are no other conflicting declarations. Perhaps you are confused by the MSIE workaround whereby the text-align property is applied to a parent element with value of center (which hasn't been used here)?

    Mike

  4. #4
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by pissa
    Code:
    <style type="text/css">
    <!--
    body {
    	background:#FFFF00;
            margin: 0 auto;
            width: 80%;
            text-align: left;
    }
    //-->
    </style>
    Where width: 80% is equal to the width .... you can use % or px or em .... the margin property is what will center the whole page and text-align will ensure that all of your text is justified normally
    The OP wants to center the div vertically.

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

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
  •