CSS边距自动不居中 [英] CSS margin auto not centering

查看:105
本文介绍了CSS边距自动不居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尽可能简化了代码,但仍然无法将其居中.我相信我对CSS的经验不足,不能让我看到非常简单的内容.

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.

如果任何人也知道CSS的一些好资源,那就太好了.我已经阅读了许多CSS书籍的各个部分,但都非常基础,涵盖了同一件事.

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标记:

/* 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

index.html

<html>
  <body>

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

  </body>
</hml>

推荐答案

如果要使用margin:auto进行居中,则将显示更改为阻止".不适用于内联元素.

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

这篇关于CSS边距自动不居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆