相关疑难解决方法(0)

为什么没有margin-top:auto和margin-bottom:auto和left左右对应的一样?

如果我像这样设置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

19
推荐指数
1
解决办法
2万
查看次数

标签 统计

css ×1