0

While I am creating a website I have given margin:0 auto for main div. It aligned properly but while I am zooming out the window in IE it is going to left alignment.

  <style>
    body         { margin:0; padding:0 }
    #container   { margin:0; padding:0 }
    #container p { margin:0; padding:0 }
  </style>
  <html>
    <body>
      <div id="container"> <p>Chriz</p> </div> 
    </body>
  </html>
3
  • Which version of IE, and which version of Windows? These things matter... Commented Feb 26, 2013 at 11:28
  • 2
    You should post some example code. Commented Feb 26, 2013 at 11:28
  • <style> body{margin:0;padding:0} #container{margin:0;padding:0} #container p{margin:0;padding:0} </style> <html> <body> <div id="container"> <p>Chriz</p> </div> </body> </html> Commented Feb 26, 2013 at 11:34

2 Answers 2

1

Do you have a fixed width on it? it should read

#mainDiv{
    margin:0 auto;
    width: 900px;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This will center align a block element. However you have to consider this bad practice as you are creating a fixed width element. Killer for a responsive, flexible design
0

hi now used to this css

body{
text-align:center;
}

#container{
margin:0 auto;
text-align:left;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.