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
    New Coder
    Join Date
    Oct 2008
    Location
    India, Banglore
    Posts
    50
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation centering a layout in 1200px resolution??

    I have problem in centering my layout in higher resolutions.

    I gave
    Code:
    body{color:#333; background:#fff; font-family:Verdana,Arial,Helvetica,sans-serif; 
    margin:0px auto auto 0px;
    font-size:11px; line-height:normal; width:99%; border:0px solid blue; width:1000px}
    but it dint get centered. I replaced
    Code:
    margin:auto; in place of margin: 0px auto auto 0px;
    It got centered but the top menu image got repeated. It seems like the menu has taken padding-left and its repeating more than needed..

    below image shows problem when given
    margin:auto
    centering a layout in 1200px resolution??-menu.jpg

    below image shows when not given
    margin:0px auto auto 0px;
    centering a layout in 1200px resolution??-menu1.png

    Below is the code for menu

    Code:
    #block-nice_menus-1 {
    padding-left:0px;margin-left:0px;
    }
    .block-nice_menus {
      line-height: normal;
      padding:0px;
      background:url(topBG.jpg) ; /* top right; */
      height:85px;
      width:auto;
      margin:0px;
      /*max-width:97.9%;
      max-width:98.2%; */
    }
    below is the code where top-tight closing image is placed..
    Code:
    #topnav_C { display:inline; float:left; position:absolute; top:0px; left:983px; width:17px; height:90px;content; background:url(images/topRIGHT.png) no-repeat;}

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by ksanjanadevi View Post
    I have problem in centering my layout in higher resolutions.

    I gave
    Code:
    body{color:#333; background:#fff; font-family:Verdana,Arial,Helvetica,sans-serif;  font-size:11px; line-height:normal; width:99%; border:0px solid blue; width:1000px}
    but it dint get centered. I replaced
    Code:
    margin:auto; in place of margin: 0px auto auto 0px;
    It got centered but the top menu image got repeated. It seems like the menu has taken padding-left and its repeating more than needed..

    below image shows problem when given
    Click image for larger version. 

Name:	menu.jpg 
Views:	93 
Size:	23.7 KB 
ID:	7163

    below image shows when not given
    Click image for larger version. 

Name:	menu1.png 
Views:	83 
Size:	27.3 KB 
ID:	7164

    Below is the code for menu

    Code:
    #block-nice_menus-1 {
    padding-left:0px;margin-left:0px;
    }
    .block-nice_menus {
      line-height: normal;
      padding:0px;
      background:url(topBG.jpg) ; /* top right; */
      height:85px;
      width:auto;
      margin:0px;
      /*max-width:97.9%;
      max-width:98.2%; */
    }
    below is the code where top-tight closing image is placed..
    Code:
    #topnav_C { display:inline; float:left; position:absolute; top:0px; left:983px; width:17px; height:90px;content; background:url(images/topRIGHT.png) no-repeat;}
    you must have a width smaller then window width and not auto, position: relative and margin 0 auto.

    best regards

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    margin:0px auto auto 0px;
    is equivalent to
    Code:
    margin-top:0;
    margin-right:auto;
    margin-bottom:auto;
    margin-left:0
    But you need to give auto values for your left and right margins, like
    Code:
    margin-top:0;
    margin-right:auto;
    margin-bottom:0;
    margin-left:auto
    (The short hand operates in clockwise direction)
    Or in short
    Code:
    margin:0 auto 0 auto;
    Or even short like
    Code:
    margin:0 auto;
    And as said above, you need to specify a smaller width to your element than it's container, to see the center in action.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello ksanjanadevi,
    When you use the shorthand for margin or padding it goes in a clockwise order like this: margin: top,right,bottom,left;

    Your margin:0px auto auto 0px; reads like this:
    margin-top:0;
    margin-right:auto;
    margin-bottom:auto;
    margin-left:0;


    The very basics of centering is
    • DocType
    • width
    • margin:auto;


    Like this example where you see the div #wrap is centered:
    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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	background: #FC6;
    }
    #wrap {
    	width: 800px;
    	height: 600px;
    	margin: 30px auto;
    	background: #999;
    }
    </style>
    </head>
    <body>
        <div id="wrap">
        <!--end wrap--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

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