如果我像这样设置div的CSS margin属性:
div { margin-left: auto; margin-right: auto; }
Run Code Online (Sandbox Code Playgroud)
我得到一个在页面中水平居中的div,就像这样.
但是,如果我将CSS更改为:
div { margin-top: auto; margin-bottom: auto; }
Run Code Online (Sandbox Code Playgroud)
我的div不是垂直居中的.我不需要知道一个解决方法(有很多 可用的解决方案),但我想知道这种行为的原因.为什么margin-top和margin-bottom的工作方式不一样?我错过了什么?
css ×1