CSS margin auto not centering

点点圈 提交于 2020-01-02 01:51:08

问题


I have simplified the code as much as possible, but still can't get it to center. I believe my inexperience with CSS is not allowing me to see something extremely simple.

If anyone also knows some good resources for css, that'll be great. I have read sections of many CSS books but there all very basic and cover the same thing.

CSS Markup:

/* MAIN ––––––––––––––––––––– */
html {
    /* overflow-y:scroll; */
}
body {
    /* margin:0; */
    /* position:relative; */
}
/* Form ––––––––––––––––––––– */
#form {
    margin:0 auto;
    width: 300px;
    height: 200px;
    display: inline-block;
    border: 2px solid black;
}

index.html

<html>
  <body>

    <form id='form'></form>

  </body>
</hml>

回答1:


Change the display to block if you want to use margin:auto for centering. That does not work with inline elements.



来源:https://stackoverflow.com/questions/16802728/css-margin-auto-not-centering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!